ProgrammingHardTCS NQT · Infosys

Intervals (1,4), (2,3) and (3,5) are stored as pairs in an array and qsort sorts them ascending by their second value. Which pair comes first?

  1. A. (1,4)
  2. B. (2,3)
  3. C. (3,5)
  4. D. (1,3)

Correct answer: B. (2,3)

The second values are 4, 3 and 5, so (2,3) with end 3 is smallest. Sorting by end time is the first step of the classic greedy interval scheduling method.

More C Programming questions

Exams that ask this topic