ProgrammingHard
Upper bound: in the sorted keys 1, 3, 5, 5, 5, 8, 9 (0-based), what index does bisect_right / upper_bound return for x = 5?
- A. 2
- B. 5
- C. 4
- D. 6
Correct answer: B. 5
The upper bound is the first position whose value is greater than 5, which is index 5 (the value 8). Index 2 is the lower bound, the first 5.
More C Programming questions
- To find the k-th largest of 10^6 records by score, which approach is correct and fast enough?
- To find duplicate keys among 2 x 10^5 records, which method is correct and fast enough?
- A qsort comparator must sort records by name in descending order using strcmp on char name[16] fields. Which is correct?
- An array of 10^6 records of 100 bytes each must be sorted. Which approach is correct and fast enough?
- struct S { int id; int v; }; struct S a[4] = {{1,9},{2,8},{3,7},{4,6}}; struct S b[4]; memcpy(b, a, sizeof a); b[0].v = 0; printf("%d %d"…
- struct Grid { int cell[2][2]; }; struct Grid g1 = {{{1, 2}, {3, 4}}}; struct Grid g2 = g1; g2.cell[1][1] = 0; printf("%d", g1.cell[1][1])…