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
Binary Search Finds Peak Element in LeetCode Challenge
More Relevant Posts
-
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 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 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 60 of DSA consistency Today I practiced a Binary Search Tree (BST) problem: Search in a Binary Search Tree. In this problem, we need to find a node with a given value in a BST and return the subtree rooted at that node. 🔹 Key Idea: A BST has the property: Left subtree values < root Right subtree values > root Using this property, we can efficiently search by moving left or right instead of traversing the entire tree. 📊 Complexity Analysis Time Complexity: O(h) → where h is the height of the BST Space Complexity: O(h) due to recursion stack If the tree is balanced, the complexity becomes O(log n). #DSA #Java #BinarySearchTree #CodingJourney #Consistency #LeetCode #100DaysOfCode
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
-
-
🚀 Day 74 of #100DaysOfCode Today I solved Search in Rotated Sorted Array from LeetCode using a modified Binary Search approach. 🧠 Problem Insight: Even though the array is rotated, one half is always sorted. By identifying the sorted half, we can decide where to move — left or right. ⚡ Key Learning: Instead of thinking “array is rotated ”, Think → “One side is still sorted ” 💻 Approach: Use Binary Search Check which half is sorted Verify if target lies in that half Reduce search space accordingly ⏱ Complexity: Time: O(log n) Space: O(1) #Day74 #100DaysOfCode #DSA #BinarySearch #Java #CodingJourney
To view or add a comment, sign in
-
-
🚀 Day 34 of #100DaysOfCode Solved 852. Peak Index in a Mountain Array on LeetCode ⛰️📈 🧠 Key Insight: A mountain array strictly increases to a peak and then decreases. Instead of scanning the whole array, we can use Binary Search to efficiently find the peak. ⚙️ Approach: 🔹Use binary search with two pointers left and right 🔹Compare arr[mid] with arr[mid + 1] 🔹If arr[mid] > arr[mid + 1] → peak is on the left side (including mid) 🔹Otherwise → peak is on the right side 🔹Continue until left == right, which gives the peak index ⏱️ Time Complexity: O(log n) 📦 Space Complexity: O(1) #100DaysOfCode #LeetCode #DSA #BinarySearch #Arrays #Java #ProblemSolving #InterviewPrep #LearningInPublic
To view or add a comment, sign in
-
-
Day 60: Work Smarter, Not Harder 🧠 Problem 1689: Partitioning Into Minimum Number Of Deci-Binary Numbers Today’s problem was a classic example of why you should analyze test cases before over-engineering a solution. The Strategy: • Initial Fail: Tried calculating the maximum deci-binary value before the target. Too complex, didn't work. 💀 • The "Aha" Moment: Realized that since deci-binary numbers only use 0s and 1s, the minimum number of partitions needed is simply determined by the largest digit in the string. • Logic: If you have a '9', you need at least nine deci-binary numbers to sum up to it. O(N) time, O(1) space, and zero stress. Sometimes the hardest part of a "Medium" problem is realizing how easy it actually is. 🚀 #LeetCode #Java #Algorithms #ProblemSolving #DailyCode #CleanCode
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 6 – DSA Practice Solved Remove Duplicates from Sorted Array today. 📌 Problem: Given a sorted array, remove duplicates in-place such that each element appears only once and return the new length. 💡 Insight: Use the two-pointer approach — one pointer tracks unique elements, while the other scans the array to update values in-place. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening my understanding of in-place array manipulation and pointer techniques. #Java #DSA #LeetCode #TwoPointers #CodingInterview
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