## Toppr Interview Question for Software Engineer / Developers

• 0

Country: India
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
0
of 0 vote

Use KD BST tree for storing these events and perform the range search. It gurantees to be O(nlogn) times in worst case can go upto n.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Sort by start date, probably into a multimap. Than one more path is enough to mark overlaps.

Comment hidden because of low score. Click to expand.
0
of 0 vote

What about creating an arrany of "int Day[30]". Initialize with zero. Increment the value at each index once a date a found on that day.

Comment hidden because of low score. Click to expand.
0
of 0 vote

Create a binary search tree which stores the end points of each time interval. Each node should also store what time interval its value comes from.

Notation: dates are represented in MMDD format.
Nodes: (1010, 0), (1015, [0, 2]), (1012, 1), (1014, 1), (1024, 2), (1023, 3), (1103, 3), (1004, 4), (1005, 5).

After constructing this BST, for each time interval, perform a search looking for a value that is contained in the given interval AND does not belong to the given interval. These searches should be directed towards branches that may lead to time conflicts, i.e. if we got the interval [1015, 1024] and we face a node with value 1010, naturally we need to conduct the search to the branch in the right.

Assuming that we have the ability to create a balanced BST, the construction phase is O(nlogn) and the search phase is also O(nlogn).

Comment hidden because of low score. Click to expand.
0

While my solution seems to work for this problem, it is not correct for the general case (in which you pick just one interval and wants to get the conflicts for it). This is because my algorithm doesn't cover the case where an interval completely contains another one, e.g. [1000, 1005] and [1001, 1004].

Thus, you'd better use Interval Trees, which are 100% correct.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

### Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

### Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.