My Calendar

Given ‘N’ events each with a ‘start’ and ‘end’ time in the form of intervals such that it represents a booking on the half-open interval [start, end), i.e., the range of real numbers x such that start <= x < end. Initially, the calendar has no events. A new event can be added to the calendar, if adding the event will not cause a triple booking. A triple booking happens when three events have some non-empty intersection (i.e., there exists a time common to all the 3 events).

Your task is to process the 'N' events, and for each of the events, add that event to the calendar and return ‘True’, if the event can be added to the calendar successfully without causing a triple booking. Otherwise, return ‘False’ and do not add that event to the calendar.

Input format:
The first line of input contains an integer ‘T’, denoting the number of test cases. 

The first line of each test case contains an integer ‘N’, which represents the total number of events.

Then the next ‘N’ lines contain two space-separated integers 'Start' and 'End', denoting the starting and ending times of the 'N' intervals. 
Output format:
For each test case, print 'N' space-separated 'True' or 'False' denoting the status of each event.  (‘True’ if the addition of an event to the calendar does not cause triple booking, ‘False’ otherwise).

Output for each test case is printed on a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given functions.
Constraints:
1 <= T <= 10
1 <= N <= 1000
0 <= Start , End <= 10^9

Time Limit: 1 sec
CodingNinjas
author
2y
Brute Force Approach
  • This is a brute force approach where we will maintain two lists.
    • The first list will contain all the events that are booked at least once.
    • The second list will contain all the events...read more
CodingNinjas
author
2y
Solution using HashMap
  • The idea behind this approach is that we will maintain a HashMap in which:
    • We will store the timestamp for each unit of time. Initially, all the timestamps will be 0. In the case ...read more
Help your peers!
Add answer anonymously...
Microsoft Corporation SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter