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
Binary Search Solution for LeetCode 35
More Relevant Posts
-
Day 14 of Daily DSA 🚀 Solved LeetCode 153: Find Minimum in Rotated Sorted Array ✅ Approach: Used Binary Search to locate the minimum element in a rotated sorted array. At each step, compared nums[mid] with nums[end] to determine which half is unsorted and contains the minimum. By shrinking the search space intelligently, the minimum element is found efficiently. A great example of how Binary Search adapts to rotated arrays. ⏱ Complexity: • Time: O(log n) • Space: O(1) 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.66 MB (Beats 87.66%) Binary Search mastery keeps leveling up 💪 #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 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 DSA practice 🚀 (Binary Search on Answer) Today’s main focus was: 🆕 #875 – Koko Eating Bananas This problem was a great reminder that binary search isn’t just for sorted arrays — it can also be applied on the answer space. Instead of searching for an index, we search for the minimum possible eating speed that satisfies the given constraint. It really strengthened my understanding of: Setting correct search boundaries Designing a valid feasibility check Avoiding off-by-one errors Also revised a few earlier binary search problems to reinforce fundamentals: 🔁 #35, #278, #33, #153 Slowly getting more comfortable with advanced binary search patterns 🔥 #DSA #LeetCode #BinarySearch #ProblemSolving #Java #Consistency #LearningInPublic #100DaysOfCode
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
-
-
#100DaysOfCode 👉 LeetCode #35 – Search Insert Position Binary Search is not just about finding elements 👀 🔹 Idea: Applied Binary Search on a sorted array. If the target is found, return its index. If not found, the `left` pointer itself gives the correct position where the element should be inserted. Time Complexity: O(log n) Space Complexity: O(1) ✔ Strengthened binary search intuition ✔ Understood pointer movement deeply ✔ Learned how insertion logic naturally emerges from search 💡 Takeaway: Binary Search answers more than “found or not” — it also tells where something belongs. Building strong DSA fundamentals in Java, one problem at a time. Open to feedback and better approaches 👋 Day 9 ✅ #LearnInPublic #100DaysOfCode #DSA #Java #BinarySearch #ProblemSolving #SoftwareEngineer #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Imagine searching for a number in a list of 1 million sorted numbers. Would you check them one by one? Or eliminate half of the list every step? 🚀 Day 74/365 — DSA Challenge Solved: Binary Search The Problem You're given a sorted array and a target value. Return the index of the target if it exists. Otherwise return -1. 💡 The Idea Behind Binary Search Binary Search works by dividing the search space in half every step. Steps: 1️⃣ Start with the middle element 2️⃣ If it equals the target → return index 3️⃣ If target is larger → search right half 4️⃣ If target is smaller → search left half Repeat until the element is found. ⏱ Time: O(log n) 📦 Space: O(1) Day 74/365 complete. 💻 291 days to go. Code 👇 https://lnkd.in/dad5sZfu #DSA #Java #LeetCode #Algorithms #BinarySearch #LearningInPublic
To view or add a comment, sign in
-
-
Day 16 of Daily DSA 🚀 Solved LeetCode 75: Sort Colors ✅ Approach: Used the Dutch National Flag algorithm with three pointers. start → tracks position for 0s mid → current element end → tracks position for 2s By swapping elements in-place, the array is sorted in one pass without using any built-in sort. ⏱ Complexity: • Time: O(n) — single traversal • Space: O(1) — in-place sorting 📊 LeetCode Stats: • Runtime: 0 ms (Beats 100%) ⚡ • Memory: 43.63 MB (Beats 42.09%) A classic problem that perfectly demonstrates pointer-based thinking. #DSA #LeetCode #Java #BinarySearch #TwoPointers #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 2 #SDE Solved: • Search in Rotated Sorted Array II • Find Minimum in Rotated Sorted Array II Key Learning: Duplicates can break the usual binary search logic because it's harder to determine the sorted half. In such cases, shrinking the search space (low++ / high--) helps continue the search. #LeetCode #DSA #BinarySearch #SoftwareEngineering #Java
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