educative.io

Question regarding why check low > 0

Why was there a check of low > 0: then return low - 1 in the binary search?


Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: 'K' Closest Numbers (medium) - Grokking the Coding Interview: Patterns for Coding Questions

Hello @Ankit_Nayak,
The code can work without this check as well. This check is added for a different implementation. I will talk to the author about this.
Hope this helps