🚀 Day 65 of My LeetCode Journey 🚀 🔹 Problem: Find the Duplicate Number (Binary Search Approach) Today, I realized that binary search is not always about searching in a sorted array… Sometimes, we apply binary search on the range of values, not the array itself ✅ 🧠 Key Insight: Choose a mid value. Count how many values in the array are <= mid. If the count is more than mid, the duplicate is in the left half. Otherwise, it's in the right half. We keep narrowing the range until start and end meet — that number is the duplicate. ⚙️ Time Complexity: O(n log n) (no array modification, no extra space) 🧠 Learning: Before jumping to brute-force or extra space solutions, try to reason about the properties of the input. Sometimes the pattern is hidden in the constraints, not in the array. 🔸 Continuous learning. 🔸 Continuous improvement. #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #ProblemSolving #LearningEveryday #BinarySearch #TechSkills
Finding Duplicate Number with Binary Search
More Relevant Posts
-
🚀 Day 51 of My LeetCode Journey 🚀 💡 Problem: Binary Search 🧠 Concept: Binary Search is one of the most fundamental algorithms — it efficiently searches a sorted array by repeatedly dividing the search space in half. If the target value is equal to the middle element, return the index. If the target is smaller, search the left half; if larger, search the right half. ⚙️ Complexity: ⏱ Time: O(log n) 💾 Space: O(1) ✨ Learning: Binary search is not just an algorithm — it’s a mindset to “divide and conquer.” Mastering it helps in many advanced problems like searching in rotated arrays, finding peaks, and solving range queries efficiently. #100DaysOfCode #LeetCode #CodingJourney #Java #DSA #BinarySearch #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 58 of My LeetCode Journey 🚀 🔹 Problem: Search Insert Position 🔹 Topic: Binary Search (Fundamental DSA Technique) Today’s challenge focused on enhancing one core skill: thinking in terms of boundaries and decisions. The task was simple — in a sorted array, find the index of the target element. If it doesn’t exist, return the index where it logically should be inserted. What made this problem interesting is that instead of searching linearly, we leverage Binary Search, which reduces the operations drastically. ✅ Key Takeaways & Learning: Binary Search is not just used to find something — it can also determine the correct position for insertion. Understanding how low, mid, and high move helps build clear logic flow. The index where the search ends (low) gives the correct insert position, even if the element doesn't exist. Rewriting brute-force logic into binary search trains the brain to think in terms of optimization. ⏱️ Complexity Analysis: MetricValueTimeO(log n)SpaceO(1) 🌱 Personal Reflection: Every binary search problem improves clarity of thought. From checking a value to identifying a boundary or insert point — the mindset shifts from “finding an element” to “solving a pattern.” #100DaysOfCode #LeetCode #DSA #BinarySearch #Java #ProblemSolving #LearningInPublic #TechJourney #ConsistencyIsKey
To view or add a comment, sign in
-
-
🚀 Day 49 of My LeetCode Journey 🚀 Problem: LeetCode 442 — Find All Duplicates in an Array 🧩 Problem Statement: Given an array of integers where each number is in the range [1, n], some numbers appear twice while others appear once. Return all numbers that appear twice in O(n) time and O(1) extra space. 💡 Approach (In-place Marking Technique): Since each number maps to an index, we can use the array itself as a marker: For each element x, go to index abs(x) - 1 If the number at that index is already negative → x is a duplicate Otherwise, mark it as visited by making it negative ⏱️ Complexity: Time: O(n) Space: O(1) 🌟 Key Takeaway: Sometimes, the smartest solutions come from observing patterns in constraints — like using the array itself as a memory map! 💭 #Day49 #LeetCode #CodingJourney #Java #DSA #ProblemSolving #100DaysOfCode #LeetCodeSolutions #LearningEveryday
To view or add a comment, sign in
-
-
🚀 Day 23 of #50DaysLeetCodeChallenge Problem: Binary Search (LeetCode 704) — a timeless classic that reminded me how elegance in programming often lies in simplicity. 🎯 🧠 Thought Process: When dealing with sorted data, you don’t need to search everything — just guide your logic efficiently. Binary Search embodies this idea perfectly: divide, compare, and conquer. It’s all about making smarter moves, not more moves. ⚙️ Approach: 🔹 Initialized two pointers — low and high — to define the search boundaries. 🔸 Calculated the midpoint each time and compared it with the target. 🔹 Adjusted the range intelligently, narrowing down until the target was found (or confirmed missing). 🔸 Returned the index if found, else -1. 📊 Efficiency: ✅ Time Complexity: O(log n) ✅ Space Complexity: O(1) ⏱️ Runtime: 0 ms — Beats 100% of Java submissions! ⚡ 💭 Key Takeaway: Binary Search teaches that speed isn’t always about doing more work, but about doing the right work. It’s a clear reminder that logic and precision go hand in hand when optimizing performance. 💫 Big thanks to Trainer Shishir chaurasiya and PrepInsta for constantly fueling my journey toward sharper logic and smarter problem-solving! 🚀 #LeetCode #Day23 #50DaysOfCode #ProblemSolving #Java #AlgorithmDesign #BinarySearch #CodingChallenge #PrepInsta #DSA #TechLearning #LogicBuilding #DeveloperJourney #ProgrammingLife #CodingLife
To view or add a comment, sign in
-
-
🚀 Day 54 of My #100DaysOfLeetCode Challenge 🚀 Today I worked on a problem related to making parentheses valid — a classic stack-based problem that tests your understanding of balanced brackets and edge cases. 💡 Problem: Given a string containing only '(' and ')', determine the minimum number of parentheses that must be added to make the string valid. 🧠 Concepts Used: Stack data structure String traversal Counting unmatched parentheses 🧩 Approach: Traverse through the string character by character. Use a stack to track unmatched '('. When encountering ')', pop from the stack if possible, else increment the counter. Finally, the total unmatched parentheses = stack size + counter. #100DaysOfCode #LeetCode #Java #ProblemSolving #CodingJourney #DSA #WomenInTech #TechLearning #CodeNewbie
To view or add a comment, sign in
-
-
🚀 Day 54 of my LeetCode Journey 🚀 Today, I worked on Search in Rotated Sorted Array II. 🔍 Key takeaway: This problem looks similar to searching in a rotated sorted array, but the twist is duplicates. Duplicates make it difficult to identify which half of the array is sorted. Instead of giving up — we adapt the binary search! ✅ Logic used: If nums[mid] == nums[right]: we can't decide the sorted half → shrink the search space (right--). Else, check which half is sorted and move the pointers accordingly. 🧠 Concept learned: Sometimes, when data is ambiguous (like duplicates), instead of forcing a direction — reduce uncertainty first. 💻 Skills improved: • Binary Search • Handling ambiguous cases • Optimizing decision-making logic Excited to continue improving one problem at a time. Consistency > Speed 🔥 👨💻 "Every problem teaches something — even if it looks like just another binary search." #100DaysOfLeetCode #Day54 #codingjourney #java #problemsolving #binarysearch #leetcode #learningeveryday
To view or add a comment, sign in
-
-
Day 48 of #50DaysOfLeetCodeChallenge Problem : Daily Temperatures 💡Approach: Used a monotonic stack to store indices of temperatures. For each day, I checked if the current temperature is higher than the one at the top of the stack. If yes, that means we’ve found a warmer day — so I popped the index and calculated the number of days waited. This gave an efficient O(n) solution instead of checking every pair. 🔥Key Takeaways: Learned how stacks can simplify problems involving “next greater element.” Improved understanding of monotonic structures and how they reduce unnecessary comparisons. Continuing my journey of learning, growing, and coding every day! #LeetCode #50DaysOfCode #Java #DataStructures #Stack #ProblemSolving #CodeToLearn #CharuCodes
To view or add a comment, sign in
-
-
🚀 Day 71 of My LeetCode Journey 🚀 Problem : Valid Parentheses Today I solved Valid Parentheses, a classic stack-based problem that checks whether a sequence of brackets is balanced. 🔍 Key Idea: Use a Stack to track opening brackets. Push ( { [ onto the stack When you see a closing bracket, check if it matches the top of the stack If it doesn't match, the string is invalid In the end, stack must be empty 🧠 Concepts Practiced: Stack operations String traversal Matching bracket logic Clean conditional validation 💡 Learning: This problem reinforces how stacks are perfect for handling “last opened, first closed” scenarios. It’s simple but builds strong fundamentals for parsing and expression evaluation problems. #100DaysOfCode #LeetCode #Java #DSA #CodingJourney #Stack #ProblemSolving #LearningEveryday #TechCareer #Programmer
To view or add a comment, sign in
-
-
Day-90 of #100DaysOfCodeChallenge 🚀 ✨ Daily LeetCode Challenge – Problem 2536: Increment Submatrices by One Today’s problem was a great exercise in optimizing 2D range updates using a difference matrix + prefix sums approach. Instead of updating each cell inside every query (which is too slow for large constraints), I used an efficient technique that reduces the complexity from O(q·n²) to O(n² + q) — and it worked! 🚀 Happy to see the solution get accepted with solid performance. 💡 🧩 Key Takeaway: Mastering prefix-sum tricks (1D & 2D) can massively improve performance on problems involving repeated range updates on LeetCode. 📈 Results: ✔ Accepted ✔ 9ms runtime ✔ Optimized solution ✔ Beats ~90% submissions On to the next challenge! 💪 #LeetCode #DailyChallenge #Java #ProblemSolving #DSA #CodingJourney #WomenInTech #LearningEveryday
To view or add a comment, sign in
-
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
Binary search done 🔥