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?
- A. (1,4)
- B. (2,3)
- C. (3,5)
- 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
- Which of these statements are well defined by the C standard? I. uint8t x = 255; x = x + 1; leaves x equal to 0. II. int a = INTMAX; a + 1…
- What is the sum of the decimal digits of 2^20 = 1048576?
- uint16t a = 40000, b = 40000; uint32t s = a + b; What is s?
- uint32t x = 0x80000001u; x = (x << 1) | (x >> 31); What is x?
- unsigned char c = 0x7F; c = c 2 + 2; What is c?
- For the array {4, 1, 3}, how many index pairs i < j have a[i] > a[j]? These pairs are called inversions.