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?

  1. A. 4
  2. B. 2
  3. C. 3
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic