Question DSA-SRCH-0072
HardWhich bug often makes binary search loop forever when searching for the last position where a condition holds?
- A.
Using integers
- B.
Sorting the array
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Searching and Binary Search question
Which bug often makes binary search loop forever when searching for the last position where a condition holds?
Using integers
Sorting the array
Sign up free to see the answer and a step-by-step explanation.
Using mid = (lo + hi) // 2 with lo = mid, which never moves when hi = lo + 1
Using hi = mid − 1