My Calendar Problem Statement

Given N events, each represented with a start and end time as intervals, i.e., booking on the half-open interval [start, end). Initially, the calendar is empty. A new event can be added only if it does not cause a triple booking, where a triple booking means any three events have a common overlapping time.

Task:

Process the N events, and for each, determine if it can be added to the calendar without causing a triple booking. Return 'True' if it can be added successfully, otherwise return 'False'.

Input:

The first line contains an integer ‘T’, the number of test cases. For each test case, the first line contains an integer ‘N’, the number of events. The next ‘N’ lines contain two space-separated integers ‘Start’ and ‘End’ for the event intervals.

Output:

For each test case, print 'N' space-separated 'True' or 'False' for each event indicating whether it can be added without causing a triple booking. Output for each test case should be on a separate line.

Example:

Input:
2
3
10 20
15 25
20 30
2
5 10
15 20
Output:
True False True
True True

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 1000
  • 0 ≤ Start, End ≤ 109
Note:
You are not required to print anything as input/output handling is managed elsewhere. Implement the given functions accordingly.
Be the first one to answer
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

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