DEV Community

Saranya R
Saranya R

Posted on

Guess the Number

Approach Explanation (ノ◕ヮ◕)ノ*:・゚✧

  1. I used binary search between 1 and n.
  2. I guessed the middle number (mid).
  3. If the guess was correct (res == 0), I returned it.
  4. If the guess was too high (res == -1), I moved the search to the left half.
  5. If the guess was too low (res == 1), I moved the search to the right half.
  6. This process continued until I found the picked number.

Method Used:ヽ( ̄▽ ̄)ノ

  • Binary search technique
  • Midpoint guessing
  • API feedback
  • In‑place logic
  • Efficient runtime

Top comments (0)