Binary Search with APIs and Decision Functions

📘 DSA Journey — Day 37 Today’s focus: Binary Search with APIs / decision functions. Problems solved: • Guess Number Higher or Lower (LeetCode 374) • First Bad Version (LeetCode 278) Concepts used: • Binary Search • Decision-based search (using API feedback) • Search space reduction Key takeaway: Both problems are classic examples of binary search on answers using an external API. In Guess Number Higher or Lower, we use the guess() API: • If guess is too high → move left • If too low → move right • If correct → return mid In First Bad Version, we use the isBadVersion() API: • If current version is bad → search left to find the first occurrence • Else → search right The key idea is: We don’t know the exact value, but we can narrow down the search space based on feedback. This pattern is useful in problems where: • A condition is monotonic (false → true transition) • We need to find the first/last occurrence of a condition Time complexity remains O(log n). Continuing to strengthen binary search intuition and consistency in problem solving. #DSA #Java #LeetCode #CodingJourney

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories