Flatten Binary Tree to Linked List in Order of Preorder Traversal

Problem Given the root of a binary tree, flatten the tree into a “linked list”: The “linked list” should use the same TreeNode class where the right child pointer points to the next node in the list and the left child pointer is always null. The “linked list” should be in the same order as a pre-order traversal of the binary tree. Examples Example 1: ...

Check if Intervals Overlap

Problem Given a set of intervals, find out if any two intervals overlap. Example: Intervals: [ [1,4], [2,5], [7,9] ] Output: true Explanation: Intervals [1,4] and [2,5] overlap Solution Method 1 - Sorting Let’s take the example of two intervals (‘a’ and ‘b’) such that a.start <= b.start. There are three possible scenarios: ...

Maximum Intervals Overlap Count

Problem Find maximum intervals overlap. OR There is number of elephants time span given, here time span means, year of birth to year of death. You have to calculate the period where maximum number of elephants are alive. OR Consider a big party where a log register for guest’s entry and exit times is maintained. Find the time at which there are maximum guests in the party. Note that entries in register are not in any order. ...

Linked List Cycle 4 - Delete cycle

Problem Given head, the head of a linked list, determine if the linked list has a cycle in it. Return true if there is a cycle in the linked list. Otherwise, return false. Examples Example 1 Input: head = [0, 1, 3, 2, 4] output: [0, 1, 3, 2, 4] Explanation: Cycle starts at node 2 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy