#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
Binary Search Algorithm in Java: Finding and Insertion Position
More Relevant Posts
-
#100DaysOfCode 👉 LeetCode #278 – First Bad Version This problem is a clean example of how Binary Search is used to find a transition point, not just a value. 🔹 Problem Insight: Once a version becomes bad, all versions after it are also bad. That creates a monotonic search space — perfect for Binary Search. 🔹 Idea: Applied Binary Search on versions [1 … n]. • If mid version is bad → move left • If mid version is good → move right After the loop, the `left` pointer directly points to the first bad version. ⏱ Time Complexity: O(log n) 📦 Space Complexity: O(1) ✔ Strengthened boundary-based binary search ✔ Learned how APIs affect search logic ✔ Understood why returning `left` gives the correct answer 💡 Takeaway: Binary Search is not only about finding elements — it’s about locating **change points** efficiently. Building strong DSA fundamentals in Java, one problem at a time 🚀 Day 11 ✅ #LearnInPublic #Java #DSA #BinarySearch #LeetCode #ProblemSolving #SoftwareEngineering #CodingJourney
To view or add a comment, sign in
-
-
Day 46 of #100DaysOfLeetCode 💻✅ Solved #374. Guess Number Higher or Lower problem in Java. Approach: • Used Binary Search to efficiently guess the number. • Calculated mid using low + (high - low) / 2 to avoid overflow. • Used the guess(mid) API to check if the number is higher, lower, or correct. • Updated the search range accordingly until the number was found. Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.68 MB (Beats 97.84% submissions) Key Learning: ✓ Practiced implementing binary search on a real problem ✓ Learned how to safely calculate mid to prevent integer overflow ✓ Strengthened problem-solving skills with search algorithms Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
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
-
Stop writing code that “just works.” Day 45 / 100 Days of DSA Problem: Find a pair from two arrays whose sum is closest to a target. First approach: Nested loops. Better approach: Two pointers (since arrays are sorted). Move intelligently based on the sum. Time Complexity: O(n + m). Same answer. Smarter thinking. Day 45 lesson: Don’t stop at “it works.” Push for optimal. #Day45 #100DaysOfCode #DSA #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 34/100 Today I solved Search in Rotated Sorted Array II — a tricky variation of binary search with duplicates! 🔍 Problem Insight: Array is sorted but rotated Duplicates make it harder to decide which half is sorted. 🧠 Key Learning: When nums[low] == nums[mid] == nums[high], we shrink the search space Otherwise, identify the sorted half and decide where target lies. ⚡ Approach Used: Modified Binary Search Carefully handled edge cases with duplicates. 💡 Time Complexity: Best/Average: O(log n) Worst (due to duplicates): O(n). 💻 What I Learned: Duplicates can break normal binary search logic. Always handle ambiguous cases by reducing search space Patience is key in edge-case-heavy problems 😄. #DSA #BinarySearch #LeetCode #Java #CodingJourney #ProblemSolving #100Daysofcode #day34
To view or add a comment, sign in
-
-
🚀 Day 25 of Solving DSA Problems 🧠 Pattern Learned: Prefix Sum + HashMap Today I learned one of the most powerful patterns for solving subarray problems efficiently. 💡 Key Idea: If the difference between two prefix sums equals k, then the subarray between them has sum k. So while traversing the array: keep adding to prefix sum check if (currentSum − k) was seen before if yes → we found a valid subarray ⚡ This avoids checking all subarrays and reduces complexity from O(n²) → O(n). ⏱ Complexity: Time → O(n) Space → O(n) 🔥 Lesson: Prefix sum turns a range problem into a lookup problem using hashing — and that’s a game-changer. Consistency builds clarity 📈 #DSA #Java #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
Day 30 of #100DaysOfLeetCode 💻✅ Solved #108. Convert Sorted Array to Binary Search Tree on LeetCode using Java. Approach: • Used Divide and Conquer strategy • Selected the middle element as the root to maintain balance • Recursively built the left subtree using left half of array • Recursively built the right subtree using right half of array • Ensured the tree remains height-balanced at every step Performance: ✓ Runtime: 0 ms (Beats 100.00% submissions) ✓ Memory: 45.18 MB (Beats 44.10% submissions) Key Learning: ✓ Understood how sorted arrays can directly map to balanced BST ✓ Strengthened recursion fundamentals in tree construction ✓ Improved understanding of height-balanced binary trees Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearchTree #Recursion #DivideAndConquer #ProblemSolving #CodingJourney #100DaysOfCode
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 45 of #100DaysOfLeetCode 💻✅ Solved Simple #268. Missing Number problem in Java. Approach: • Calculated the expected sum of numbers from 0 to n using the formula n(n+1)/2 • Traversed the array and calculated the actual sum of the elements • Subtracted the actual sum from the expected sum • The difference gives the missing number in the array Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 47.60 MB (Beats 29.84% submissions) Key Learning: ✓ Practiced using mathematical formulas to simplify problems ✓ Learned how sum comparison can help find a missing element efficiently ✓ Strengthened problem-solving skills with arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🎯 Day 100 of #100DaysOfCode 🔥 What a way to wrap it up! Solved LeetCode #3666 – Minimum Operations to Equalize Binary String ✅ A problem that blends math, parity logic, and careful case analysis—not your usual binary flip question. Key takeaways: -> Count-based optimization over brute force -> Handling even/odd operation patterns smartly -> Early exits = cleaner & faster logic -> Thinking in terms of operations feasibility rather than simulation 🧠 Language: Java -> Runtime: 0 ms (Beats 83.87%) -> Memory: 47.90 MB 100 days. Countless problems. One habit built: consistency 💪 Onward to harder problems and deeper concepts 🚀 #LeetCode #Java #DSA #BinaryStrings #ProblemSolving #Consistency #100DaysChallenge
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