ProgrammingHard
In a sorted array with duplicates, which index does a lower_bound search return for the key 5 in [1, 5, 5, 5, 8]?
- A. 2
- B. 1
- C. 3
- D. 4
Correct answer: B. 1
lower_bound returns the first position whose value is not less than 5, which is index 1.
More C Programming questions
- Two sorted struct arrays of sizes n and m are merged into a new array. How many elements does the merged array hold?
- A struct array of n records is sorted by key. The code stores a record index inside each record before sorting, so that it can recover the…
- A histogram of sorted keys [1, 1, 2, 2, 2, 3] counts the adjacent equal pairs. How many such pairs are there?
- The largest gap between consecutive values of the sorted list 1, 4, 9, 16 is which value?
- The median of the sorted keys 2, 4, 6, 8 with integer division is which value?
- In the keys 3, 1, 3, 2, 1, the mode (most frequent key) is needed. With ties, the smallest key wins. Which is the mode?