Find First and Last Position of Element in Sorted Array | LeetCode

🚀 Day 9/100 – Find First and Last Position of Element in Sorted Array | LeetCode (Medium) Continuing my #100DaysOfChallenges journey. Today’s problem strengthened my understanding of Binary Search variations. 🧩 Problem: Given a sorted array, find the starting and ending position of a given target value. If the target is not found, return [-1, -1]. Constraint: Must run in O(log n) time. 🧠 Approach Used: Modified Binary Search (Lower Bound + Upper Bound) Instead of scanning the array linearly, I applied: ✔️ Binary Search to find the first occurrence ✔️ Binary Search to find the last occurrence ✔️ Carefully adjusted search boundaries ✔️ Maintained O(log n) complexity Core idea: When target found → continue searching left (for first position) When target found → continue searching right (for last position) ⏱ Complexity: Time: O(log n) Space: O(1) 🎯 Key Learning: Binary Search has many powerful variations Boundary conditions are critical Interview questions often test edge-case precision This problem strengthened my: 👉 Algorithm optimization thinking 👉 Boundary handling skills 👉 Confidence with search-based problems 91 days to go 🚀 #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #CodingJourney #TechGrowth #AIML

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories