Data Structures & AlgorithmsHardProduct company OA · Infosys pattern
The intervals [1, 4], [6, 8], [2, 3], [8, 10], [12, 13] are sorted by start and merged (intervals that touch at an endpoint also merge). How many intervals remain?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
Sorted: [1,4], [2,3], [6,8], [8,10], [12,13]. [2,3] is inside [1,4]; [8,10] touches [6,8] → [6,10]; [12,13] stands alone. Result [1,4], [6,10], [12,13]: 3. Treating touching intervals as separate gives 4.
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
- A 'leader' is an element strictly greater than every element to its right (the last element is always a leader). Scanning from the right…
- The words stop, pots, opts, post, tops, spot, pot, top are grouped so that anagrams share a group (key = the sorted letters). How many…
- A stack is built from two queues with a costly push: enqueue x into the empty queue Q2, move every element of Q1 into Q2 one by one, then…
- With at most k = 2 character replacements, what is the length of the longest substring of 'AABCABBB' that can be turned into a single…
- What is the length of the longest contiguous subarray of [0, 1, 1, 0, 1, 1, 1, 0, 0, 0] with an equal number of 0s and 1s? (Map 0 to −1…
- What is the maximum sum of a non-empty contiguous subarray of the CIRCULAR array [5, −8, 3, 4, −2, 6, −9, 7] (a subarray may wrap from the…