Find Peak Element in Array with Binary Search

Imagine standing on a mountain range. Your goal is simple: Find any peak. Not necessarily the highest mountain — just a point that is higher than its neighbors. That's exactly what today's problem was about. 🚀 Day 77/365 — DSA Challenge Solved: Find Peak Element The Problem A peak element is a number that is greater than its neighbors. Given an array, return the index of any peak element. 💡 My Approach This problem can be solved using Binary Search. Key observation: If nums[mid] < nums[mid + 1] It means the peak must be on the right side. Otherwise, the peak lies on the left side (including mid). So we keep shrinking the search space until: start == end That index will be a peak element. Binary search moves toward the increasing slope until it reaches the peak. Complexity ⏱ Time: O(log n) 📦 Space: O(1) Day 77/365 complete. 💻 288 days to go. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #BinarySearch #Algorithms #LearningInPublic

  • text

To view or add a comment, sign in

Explore content categories