Data Structures & AlgorithmsHardLeetCode-style · TCS NQT
Closed real intervals [(1, 4), (3, 6), (8, 9), (9, 12), (14, 15)] are merged whenever they overlap (sharing an endpoint counts as overlap). What is the total length covered by the union?
- A. 11
- B. 10
- C. 14
- D. 3
Correct answer: B. 10
Sort and merge: [1,4] and [3,6] become [1,6]; [8,9] and [9,12] share 9 and become [8,12]; [14,15] stays. Lengths 5 + 4 + 1 = 10. Summing the originals double-counts [3,4] (11), 14 is the span 1 to 15, and 3 is the number of blocks.
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
- Over all pairs of DIFFERENT positions of [2, 5, 3, 8, 4], take the product of each pair and sort all these products. What is the 6-th…
- Starting from [9, 6, 15, 4], repeat 3 times: take the current LARGEST element, replace it by its floor half, and keep the others. What is…
- How many substrings of "cbaebabacd" of length 3 are anagrams of "abc" (contain exactly the same letters with the same counts, in any order)?
- In "abababaabab", what is the maximum number of NON-OVERLAPPING occurrences of "aba" that can be chosen (left to right, each occurrence…
- A stack starts empty. The operations are ['push', 'push', 'pop', 'push', 'push', 'pop', 'push', 'push', 'push', 'pop', 'push']. How many…
- From "bcabcdbac" delete exactly 3 letters (the rest keep their order). What is the lexicographically LARGEST string you can obtain?