Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE
Problem: A list of intervals is [1,5], [2,3], [4,8], [7,9], [10,11]. Merge all overlapping intervals (touching at an endpoint counts as overlapping). How many merged intervals are there?
- A. 2
- B. 3
- C. 1
- D. 4
Correct answer: A. 2
Sort by start and merge while the next start does not exceed the current end. Here [1,5],[2,3],[4,8],[7,9] collapse into [1,9], leaving [10,11] separate: two merged intervals.
More Coding Interview Problems questions
- Problem: The string "aabbbcccc" is encoded by writing each letter followed by its count, e.g. "a2b3c4". What is the length of the encoded…
- Problem: What is the number of inversions in the array [2, 5, 1, 4, 3]?
- Problem: The array [3, 7, 1, 9] is used to create all non-empty contiguous subarrays. How many of them have an odd sum?
- Problem: In the array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], find the number of pairs (i, j) with i < j whose product is a multiple of 12.
- Problem: How many 5-digit numbers (10000–99999) have digits that sum to exactly 6 and begin with the digit 1?
- Problem: A string of 6 characters is formed from the letters {a, b} such that no two adjacent characters are equal. How many such strings…