Solved LeetCode 704: Binary Search with Python

🚀 Day 29 DSA Challenge – Problem 704: Binary Search A timeless classic — the foundation of efficient searching algorithms 🔍 🎯 Problem Statement: Given a sorted array nums and an integer target, find the index of target using an algorithm with O(log n) time complexity. If target doesn’t exist, return -1. 🧩 How I Solved It: Used the Binary Search technique — repeatedly dividing the search space in half. Initialized two pointers, left and right, representing the current search range. Found the middle index mid, compared nums[mid] with target: If equal → returned mid. If smaller → shifted the left boundary rightward. If greater → moved the right boundary leftward. Continued until left > right, meaning the element isn’t found. ⚙️ Performance Stats: ⏱ Runtime: 0ms (⚡ beats 100%) 💾 Memory: 13.48MB (beats 31.70%) ✅ Testcases Passed: 47 / 47 ✨ Insight: Binary Search perfectly demonstrates divide-and-conquer at its best — turning linear scans into logarithmic efficiency 🚀 #LeetCode #Problem704 #BinarySearch #Algorithm #DSA #DivideAndConquer #Python #100DaysOfCode #CodingChallenge

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories