root@coding-prodigies:~#
← All challenges

Binary Search

Find a value in a sorted array in O(log n) instead of scanning it.

🟠 HardDifficulty

The challenge

Given the sorted array [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], find the index of 13 using binary search (repeatedly halving the search range) -- not a plain linear scan -- and print the index.

Output

  
🧠 Need a hint? (Python)

Keep lo and hi pointers. While lo <= hi, check the midpoint: if it's the target you're done, if it's too small move lo up, if too big move hi down.

🚀

Like solving these?

Structured courses, hands-on exercises, and real multi-file projects are waiting -- your first project unlock is free.

Create a free account

More challenges