Day 13 of Daily DSA 🚀 Solved LeetCode 33: Search in Rotated Sorted Array ✅ Approach: Used modified Binary Search to handle rotation efficiently. At each step, identified the sorted half of the array and checked whether the target lies within that range. Based on this, adjusted the search boundaries to maintain logarithmic performance. This problem is a great example of how classic binary search logic can be extended with small observations. ⏱ Complexity: • Time: O(log n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.97 MB (Beats 45.43%) #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
Daily DSA: LeetCode 33 - Search in Rotated Sorted Array
More Relevant Posts
-
Day 15 of Daily DSA 🚀 Solved LeetCode 162: Find Peak Element ✅ Approach: Used Binary Search to efficiently find a peak element. At each step, compared the middle element with its neighbors to decide which side must contain a peak. This works because at least one peak always exists in the array. ⏱ Complexity: • Time: O(log n) — binary search on array • Space: O(1) — no extra space used 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.20 MB (Beats 75.11%) A great example of how binary search can be applied beyond just sorted arrays. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 15 of Daily DSA 🚀 Solved LeetCode 540: Single Element in a Sorted Array ✅ Approach: Used Binary Search on indices instead of values. Since elements appear in pairs, the unique element breaks the pairing pattern. By forcing mid to be even and comparing nums[mid] with nums[mid + 1], we can safely discard half of the array each time. ⏱ Complexity: • Time: O(log n) — binary search • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 52.96 MB (Beats 57.60%) A neat example of how index properties make binary search even more powerful. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
Day 29/75 — Search Insert Position Today's problem focused on applying binary search on a sorted array. Goal: Return the index of a target value if it exists. If it does not exist, return the index where it should be inserted. Approach: • Use binary search to locate the target • If the element is not found, the left pointer represents the correct insertion index Key idea: return left Because after binary search ends, left naturally points to the position where the target should be inserted. Time Complexity: O(log n) Space Complexity: O(1) 29/75 🚀 #Day29 #DSA #BinarySearch #Java #Algorithms #LeetCode
To view or add a comment, sign in
-
-
Day 14 of Daily DSA 🚀 Solved LeetCode 35: Search Insert Position ✅ Approach: Applied classic Binary Search on the sorted array. If the target exists, return its index. If not, the final value of start naturally represents the correct insert position while maintaining sorted order. This problem nicely reinforces how Binary Search can be adapted beyond just “find or not find”. ⏱ Complexity: • Time: O(log n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 44.57 MB (Beats 92.62%) Simple logic, powerful efficiency 💪 #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 Day 97 of #100DaysOfCode Solved LeetCode #1022 – Sum of Root To Leaf Binary Numbers ✅ A neat blend of DFS traversal and binary math, turning root-to-leaf paths into numbers. Key Takeaways: -> DFS with an accumulated binary value -> Using left shift (num * 2) to build numbers efficiently -> Correctly identifying leaf nodes for the final sum -> Simple recursion, strong fundamentals 🌳➡️🔢 Language: Java -> Runtime: 0 ms (Beats 100%) ⚡ -> Memory: 43.76 MB Consistency wins. Almost at the finish line 💻🔥 #LeetCode #Java #BinaryTree #DFS #Recursion #BitManipulation #ProblemSolving #100DaysOfCode
To view or add a comment, sign in
-
-
Day 26 - Single Element in a Sorted Array Technique Used: Parity-Based Binary Search Key Idea: Since every element appears twice except one, used index parity (even/odd positions) to determine which half violates the pairing rule. If pairing is correct on the left side, move right. Otherwise, move left. Time Complexity: O(log n) #Day26 #LeetCode #Java #BinarySearch #DSA #Algorithms
To view or add a comment, sign in
-
-
Day 69/100 – LeetCode Challenge ✅ Problem: #229 Majority Element II Difficulty: Medium Language: Java Approach: Extended Boyer-Moore Voting Algorithm Time Complexity: O(n) Space Complexity: O(1) Key Insight: At most two elements can appear more than ⌊n/3⌋ times. Track two candidates and their counts simultaneously. When a new element matches neither candidate, decrement both counts. Solution Brief: Phase 1: Find two potential candidates: Maintain two candidates and their counts Update based on matches or count resets Phase 2: Verify both candidates actually appear > n/3 times Add valid candidates to result list. #LeetCode #Day69 #100DaysOfCode #Array #Java #Algorithm #CodingChallenge #ProblemSolving #MajorityElementII #MediumProblem #BoyerMoore #VotingAlgorithm #DSA
To view or add a comment, sign in
-
-
Day 13 of Daily DSA 🚀 Solved LeetCode 34: Find First and Last Position of Element in Sorted Array Approach: Applied Binary Search twice to efficiently locate the range of the target element. • First pass finds the leftmost (first) occurrence • Second pass finds the rightmost (last) occurrence A boolean flag helps reuse the same logic for both searches, keeping the code clean and optimal. This ensures the required logarithmic performance on a sorted array. ⏱ Complexity: • Time: O(log n) — two binary searches • Space: O(1) — constant extra space 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 48.50 MB (Beats 11.84%) A perfect example of how modifying binary search slightly can solve range-based problems efficiently. #DSA #LeetCode #Java #BinarySearch #ProblemSolving #DailyCoding #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Tip: Two Pointer Approach for Target Sum If your array is sorted, you don’t need nested loops to find a pair with a given target sum. 👉 Use the Two Pointer Technique — simple and O(n)! 💡 How it works: • Place one pointer at the start (left) • Place another at the end (right) • Compare their sum with the target ✅ If sum is small → move left++ ✅ If sum is large → move right-- ✅ If equal → 🎯 pair found ⏱️ Complexity: Time → O(n) Space → O(1) 🔥 When to use: ✔️ Target sum in sorted array ✔️ Pair problems ✔️ Remove duplicates ✔️ Reverse problems Mastering two pointers can save you from unnecessary O(n²) solutions! #DSA #CodingInterview #Java #TwoPointers #ProblemSolving #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 22 of #100DaysOfCode Solved 34. Find First and Last Position of Element in Sorted Array on LeetCode 🔍 🧠 Key insight: To find both boundaries of a target in a sorted array, a single binary search isn’t enough. Running two binary searches—one for the leftmost and one for the rightmost occurrence—gives an optimal solution. ⚙️ Approach: 🔹Perform a binary search to find the first occurrence 🔹Perform another binary search to find the last occurrence 🔹Adjust search boundaries after finding the target to expand left/right ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development