Data Structures & AlgorithmsHardGATE CS · DSA
The intervals [15, 16], [11, 16], [4, 9], [4, 8], [8, 12], [20, 22] are sorted by start and merged (intervals that touch, like [2, 4] and [4, 6], are merged too). How many intervals remain, and what is the total length covered?
- A. 3 intervals, length 14
- B. 3 intervals, length 15
- C. 2 intervals, length 21
- D. 2 intervals, length 14
Correct answer: D. 2 intervals, length 14
After sorting by start, extend the last merged interval while the next start ≤ its end. Result: [4, 16], [20, 22] — 2 interval(s) covering 14 units (summing the raw lengths double-counts overlaps).
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- For s = "cbbbccadbcdacd", what is the length of the longest substring with at most 2 distinct characters, and how many substrings (by…
- Keys 81, 25, 26, 79, 49, 55, 59, 93 are inserted in this order into an empty table of size 11 with h(k) = k mod 11 and linear probing…
- Only the lower triangle (including the diagonal) of a 10 × 10 matrix is stored COLUMN by column in a 1-D array B starting at B[0] (indices…
- A min-stack keeps a second stack of running minimums. What is printed? python st, mn, out = [], [], [] for op in [8, "pop", 8, 8, "pop"…
- Reverse a singly linked list in groups of k (a final group shorter than k is left as it is). What is printed? python def revk(h, k): cnt…
- Print a matrix in spiral order (right, down, left, up, repeat). What is printed? python m = [[50, 81, 32, 23], [30, 61, 32, 23], [60, 51…