Tip 1: Begin by mastering data structures, then actively participate in coding contests. Make it a habit to solve at least one additional problem after each contest.
Tip 2: Challenge yourself by solving problems that are slightly above your current rating to steadily improve your skills.
Tip 3: Build a few projects using the technologies you're passionate about to strengthen your practical knowledge and showcase your abilities.
Tip 1: Build a strong portfolio, whether through competitive programming achievements or web development projects.
Tip 2: Thoroughly prepare by anticipating and practising answers to all potential questions related to your resume.
This round was scheduled for around 8 AM. The interviewer was very friendly, and I was asked to share the complete approach and code it down.



For the given binary tree: [1, 2, 3, -1, -1, 4, 5, -1, -1, -1, -1]
Start Node: 3
1
/ \
2 3
/ \
4 5
Output: 2
Explanation :
In the zeroth minute, Node 3 will start to burn.
After one minute, Nodes (1, 4, 5) that are adjacent to 3 will burn completely.
After two minutes, the only remaining Node 2 will be burnt and there will be no nodes remaining in the binary tree.
So, the whole tree will burn in 2 minutes.
Create a hashmap to map each node to its parent.
Set up pointers to point to the node with the target value.
Write a recursive function that calculates the distance to all leaf nodes.
Return the maximum distance among them.



Using BFS, we can explore all possible lock combinations, starting from "0000." At each step, we generate the neighbours of the current lock state by turning each of the four circular wheels either clockwise or counterclockwise. We then move to the next valid neighbour, as long as it isn't part of the dead. If we reach the target lock, the current number of steps will represent the minimum number of turns needed to open the lock.
This round started around 10 AM.

Median for ‘arr’ = [1,2,3,4,5] is 3.
Median for ‘arr’ = [1,2,3,4] is (2+3)/2 = 2.5.
Input:
5
1 1
1 2
2
1 5
2
Output:
1.5
2
Explanation:
MedianFinder() initialises the MedianFinder object.
Add 1 to the data structure ‘arr’, so arr = [1].
Add 2 to arr, so arr = [1,2]
Find Median of current arr, that is (1+2)/2 = 1.5.
Add 5 to arr, so arr = [1,2,5]
Find Median of current arr, that is 2.0.
I maintain two heaps (or priority queues):
- The max-heap small stores the smaller half of the numbers.
- The min-heap large stores the larger half of the numbers.
This setup gives me direct access to the one or two middle values (which are at the tops of the heaps), allowing me to get the median in O(1) time. Adding a number takes O(log n) time.
Supporting both min- and max-heaps can be somewhat cumbersome depending on the programming language, so I simply negate the numbers in the heap where I need the reverse of the default order.


Here the start of the event is included while the end is not as part of the slot i.e. the slot end right before the end.
Input:
["MyCalendarEvents", "book", "book", "book", "book", "book", "book"]
[[], [10, 20], [50, 60], [10, 40], [5, 15], [5, 10], [25, 55]]
Output:
[null, 1, 1, 2, 3, 3, 3]
Explanation:
MyCalendarEvents myCalendarEvent = new MyCalendarEvents();
myCalendarEvent.book(10, 20); // return 1, The first event can be booked and is disjoint, so the maximum k-booking is a 1-booking.
myCalendarEvent.book(50, 60); // return 1, The second event can be booked and is disjoint, so the maximum k-booking is a 1-booking.
myCalendarEvent.book(10, 40); // return 2, The third event [10, 40) intersects the first event, and the maximum k-booking is a 2-booking.
myCalendarEvent.book(5, 15); // return 3, The remaining events cause the maximum K-booking to be only a 3-booking.
myCalendarEvent.book(5, 10); // return 3
myCalendarEvent.book(25, 55); // return 3
We use a map count where time points serve as the keys. If count[t] exists, it represents the number of events happening at time t, continuing until the next time point.
Now, let’s break down the map operation: count.emplace(t, (--count.lower_bound(t))->second).
If the map already contains the key t, no insertion occurs and the map remains unchanged. count.emplace(t, value) returns a pair of in this case.
If the key t is absent, count.emplace(t, value) inserts the value and returns.
count.upper_bound(s) retrieves the first iterator after t, while --count.upper_bound(s) gets the first iterator before t, allowing us to access the event count at t. This value is then inserted into count[t].
Next, we iterate over all time points within the specified time window and increment them accordingly.
Given an array A of size n, the safe value is defined by |A[I]-A[j]|+|I-j|, find the maximum safe value in the array. (Learn)
The absolute value expressions can be expanded into different cases based on the signs of A[i] - A[j] and i - j. This gives us four cases:
A[i] - A[j] + i - j
A[i] - A[j] - (i - j)
-(A[i] - A[j]) + i - j
-(A[i] - A[j]) - (i - j)
These simplify to:
(A[i] + i) - (A[j] + j)
(A[i] - i) - (A[j] - j)
-(A[i] - i) + (A[j] - j)
-(A[i] + i) + (A[j] + j)
For each case, we need to maximize the difference between two expressions. Specifically:
Case 1: Maximize A[i] + i and subtract the minimum of A[j] + j.
Case 2: Maximize A[i] - i and subtract the minimum of A[j] - j.
We can iterate through the array once to compute the following values:
Maximum and minimum of A[i] + i.
Maximum and minimum of A[i] - i.



1. You can assume that all the meetings will happen on the same day.
2. Also, as soon as a meeting gets over if some other meeting is scheduled to start at that moment, they can then be allocated that room.
Try to solve the problem in linear time complexity.
Consider there are three meetings scheduled with timings:
1pm - 4pm
3pm - 5pm
4pm - 6pm
At the start of time, meeting 1 will be allotted room 1, which will be occupied till 4 pm hence for meeting 2 we’ll have to provide another room. At 4 pm, meeting 3 can be organized in room 1 because by that time, meeting 1 would have ended. Hence we’ll require two rooms for holding all three meetings.
To solve the problem of determining which room hosted the most meetings, you can follow this approach:
Initialization:
Use a priority queue to manage available rooms and track when each room will be free.
Use another priority queue to manage ongoing meetings, storing their end times and associated rooms.
Maintain a list to count the number of meetings hosted by each room.
Sort Meetings:
Sort the meetings based on their start times to process them in chronological order.
Process Meetings:
For each meeting, check if there are any rooms available. If there are, assign the meeting to the room with the smallest number.
If no rooms are available, determine which room will be free at the soonest. Update this room's availability and start time.
Update the end time of the meeting in the priority queue and count the meeting for the assigned room.
Handle Room Availability:
Whenever a meeting ends, the room becomes available again. Update the room's status and reinsert it into the priority queue of available rooms.
Ensure that rooms are reassigned based on the earliest meeting start times.
Determine the Most Frequent Room:
After all meetings have been processed, scan through the count list to find the room that hosted the most meetings. If there is a tie, choose the room with the smallest number.

Here's your problem of the day
Solving this problem will increase your chance to get selected in this company
How do you remove whitespace from the start of a string?