The Quest Begins (The "Why")

Honestly, I used to dread interview questions that started with “Given a sorted array…”. My first attempt was a clumsy linear scan that felt like trying to find a lightsaber in a junkyard by shaking every piece until something shiny showed up. I’d watch the clock tick, my confidence dip, and wonder if I’d ever get past the screening round.

One rainy Tuesday, after yet another rejected solution, I sat down with a cup of coffee and asked myself: Why does binary search feel like magic? The answer wasn’t in memorizing a template; it was in understanding the why behind the halving trick. Once I grasped that, the algorithm stopped being a rote incantation and became a reliable tool I could wield whenever the data was sorted.

The Revelation (The Insight)

Think of a sorted list as a hallway with doors numbered from 1 to N, and you know the prize (your target) is behind one of them. Because the doors are ordered, if you peek behind door mid and see a number smaller than the prize, you can confidently slam every door to the left shut—none of them could possibly hold the prize. The same logic works if the number is larger; you discard the right half.