ProgrammingHardTCS NQT · Infosys
The sorted array is {1, 3, 6, 6, 8}. What is the index of the first occurrence of 6?
- A. 1
- B. 2
- C. 3
- D. 4
Correct answer: B. 2
Indices 0 and 1 hold 1 and 3, and index 2 is the first 6. A lower-bound binary search returns this index in O(log n).
More C Programming questions
- How many integers in the range 0 to 15 have an even number of 1 bits in binary?
- How many 1 bits are set in 2^20 - 1 (a 32-bit unsigned value)?
- uint8t a = 16; a = a a; What is a?
- uint32t t = 2000000000u + 2000000000u; What is t?
- char buf[10]; char a = buf + 2, b = buf + 9; What does printf("%td", b - a) print?
- struct P { int x, y; } arr[4]; struct P p = arr; p += 2; What is p - arr?