Day 7/100 Today’s problem: Search Insert Position The task was to find the index of a target element in a sorted array. If the element isn’t present, return the index where it should be inserted to maintain the sorted order. Used Binary Search to solve this efficiently in O(log n) time: Compared the target with the middle element Narrowed the search space accordingly If not found, the final pointer position gives the correct insert index A simple problem, but a great reminder that mastering fundamentals is key to solving more complex challenges. Consistency is starting to pay off — one step at a time. If you're also practicing DSA, how do you approach binary search problems? #100DaysOfCode #DSA #BinarySearch #ProblemSolving #CodingJourney #TechLearning #SoftwareEngineering #LearnInPublic #Developers #CodingDaily #GrowthMindset #PlacementPreparation
Binary Search Solution for Search Insert Position
More Relevant Posts
-
🚀 Struggling to pick the right approach for DSA problems? This DSA Pattern Map is a game-changer! Instead of getting lost in hundreds of LeetCode problems, master these core patterns and you'll be able to recognize the right technique within minutes. Whether it's Two Pointers, Sliding Window, Binary Search on Answer, Monotonic Stack, or DP states — this map beautifully organizes the most important patterns across: ✅ Arrays & Strings ✅ Linked Lists ✅ Binary Search ✅ Stacks & Queues ✅ Heaps ✅ Trees ✅ Dynamic Programming ✅ Graphs Save this image. Refer to it every time you feel stuck. The secret to solving DSA problems fast isn't solving more problems — it's recognizing the pattern quickly. Which pattern do you find the hardest to spot? Drop it in the comments 👇 Tag a friend who's grinding LeetCode right now! #DSA #LeetCode #DataStructures #Algorithms #InterviewPreparation #Coding #TechJobs #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 DSA Deep Dive – Day 38 Solved Distinct Subsequences today. And I realized… Dynamic Programming is not just about finding answers. Sometimes it’s about counting possibilities under constraints. 🤯 The problem looks simple: Given two strings s and t, find how many subsequences of s equal t. Not substring. Subsequence. That means skipping is allowed… and that’s where complexity begins. 👀 Here’s what I learned 👇 • Define dp[j] = number of ways to form t[0…j-1] • Base case: dp[0] = 1 ✅ (empty string always possible) • Traverse s and update dp backwards At every character, you decide: 👉 Take this character (if it matches) 👉 Or skip it ⚙️ Transition If s[i-1] == t[j-1]: 👉 dp[j] += dp[j-1] Each match adds new ways. Brute force recursion: Exponential 💀 Optimized DP: O(n × m) ⚡ Space optimized: O(m) 🚀 💡 The Powerful Shift Instead of asking “How many subsequences overall?” Ask “How many ways can I build THIS prefix of t?” Build prefix → reach full answer. 🎯 Lesson When counting problems appear: Think in terms of: • Choices (take / skip) • Prefix building • Accumulating ways That’s DP in its purest form. Day by day getting sharper 💪 From solving → to understanding patterns 🚀 Consistency continues. Follow for more DSA breakdowns 🔥 #LeetCode #DSA #DynamicProgramming #InterviewPrep #CodingJourney #ProblemSolving #100DaysOfCode #SoftwareEngineering #TechGrowth
To view or add a comment, sign in
-
-
Day 66 on LeetCode — Binary Search 🔍✅ Today’s problem focused on one of the most fundamental and powerful techniques in DSA — Binary Search. 🔹 Approach Used in My Solution The goal was to find the index of a target element in a sorted array. Key idea in the solution: • Maintain two pointers: low and high • Calculate mid = low + (high - low) / 2 to avoid overflow • Compare nums[mid] with target: – If equal → return index – If greater → search left half – If smaller → search right half • Continue until the search space is exhausted This approach efficiently reduces the search space by half in every step. ⚡ Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Key Takeaways: • Mastered the core concept of divide and conquer • Learned how to safely calculate mid to avoid overflow • Reinforced understanding of searching in sorted arrays efficiently 🔥 Binary Search is a must-know pattern for interviews and advanced problems! #LeetCode #DSA #Algorithms #DataStructures #BinarySearch #Arrays #DivideAndConquer #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
Most people prepare for DSA the wrong way. They open LeetCode, solve random problems, and feel productive. Then the interview comes… and they freeze. Not because they didn’t practice. Because they didn’t follow a system. Here’s what actually works: DSA Roadmap → Zero to Placement Ready Foundations → Big-O, recursion, basic math Core DS → Arrays, Strings, LinkedList, Stack, Queue, HashMap, Heap Patterns → Two Pointers, Sliding Window, Prefix Sum, Binary Search Trees & Graphs → DFS, BFS, common problems Advanced → DP, Greedy, Trie, Graph algorithms Practice → Timed problems, contests, revision Random grinding is not a strategy. Pattern-based learning is. Build the system first. Confidence follows. pdfcredits: @Dinesh Varyani #DSA #DataStructures #Algorithms #PlacementPreparation #LeetCode #CodingInterview #SoftwareEngineering #Developers #Programming
To view or add a comment, sign in
-
Day 56 of My DSA Journey Today I solved LeetCode 162 – Find Peak Element on . 📌 Problem Given an array "nums", find a peak element and return its index. 👉 A peak element is one that is greater than its neighbors. You can assume: • "nums[-1] = -∞" and "nums[n] = -∞" --- 🧠 Approach – Binary Search (Optimized) Instead of checking every element (O(n)), I used Binary Search. Key Idea: • Calculate "mid" • Compare "nums[mid]" with "nums[mid + 1]" 👉 If "nums[mid] > nums[mid + 1]" → We are in a descending part, so peak lies on the left side (including mid) 👉 Else → We are in an ascending part, so peak lies on the right side Repeat until "start == end" → that index is a peak. --- ⏱ Time Complexity: "O(log n)" — Efficient binary search 📦 Space Complexity: "O(1)" — No extra space used --- 💡 Key Learnings ✔ Using binary search on unsorted-looking problems ✔ Understanding pattern-based decision making ✔ Learning that a problem can have multiple valid answers (any peak) This problem really strengthens intuition for advanced binary search patterns 🚀 --- Consistency continues — getting better every day 💪🔥 #100DaysOfCode #DSA #BinarySearch #LeetCode #Java #ProblemSolving #CodingJourney #DeveloperJourney #Programming #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 73 on LeetCode Find First and Last Position of Element in Sorted Array 🎯🔍✅ Today’s problem focused on a classic and very important Binary Search variation. 🔹 Approach Used in My Solution The goal was to find the first and last occurrence of a target in a sorted array. Key idea in the solution: • Use two separate binary searches 🔸 Find First Occurrence: • When nums[mid] >= target, move left • If nums[mid] == target, store index and continue searching left 🔸 Find Last Occurrence: • When nums[mid] <= target, move right • If nums[mid] == target, store index and continue searching right • Combine both results to get final answer This ensures we don’t just find a match, but the complete range of the target. ⚡ Complexity: • Time Complexity: O(log n) • Space Complexity: O(1) 💡 Key Takeaways: • Learned how to modify binary search to find boundaries instead of single elements • Strengthened understanding of first/last occurrence patterns • Realized how small logic changes turn binary search into powerful variants 🔥 This pattern is extremely common in interview problems! #LeetCode #DSA #Algorithms #DataStructures #BinarySearch #Arrays #ProblemSolving #Coding #Programming #Cpp #STL #SoftwareEngineering #ComputerScience #CodingPractice #DeveloperLife #TechJourney #CodingDaily #100DaysOfCode #BuildInPublic #AlgorithmPractice #CodingSkills #Developers #TechCommunity #SoftwareDeveloper #EngineeringJourney
To view or add a comment, sign in
-
-
🚀 DSA Practice — Getting Better Step by Step! 📅 Today’s Problem: Find Square Root of a Number (Floor Value) Solved using TakeUForward platform 💻 Today’s problem was a great example of applying Binary Search beyond just searching elements. 🔹 Approach Used: Binary Search on Answer Instead of checking every number, I used binary search to efficiently find the square root by narrowing down the range. ⏱ Time Complexity: O(log n) 💾 Space Complexity: O(1) 💡 Key Learning: Binary Search is not limited to sorted arrays — it can be applied to optimize problems where the answer lies within a range. This problem helped me understand how to reduce time complexity from O(n) to O(log n) by thinking in terms of search space rather than brute force. 🔥 Consistency continues — learning something new every day! takeUforward Striver #BinarySearch #takeUforwardtakeUforward #DSA #Algorithms #Coding #Java #ProblemSolving #SoftwareEngineering #Consistency
To view or add a comment, sign in
-
-
Most people don’t struggle with DSA because they’re “bad at coding.” They struggle because they try to memorize hundreds of problems instead of learning the small set of patterns behind them. Once I stopped asking: ❌ “Which LeetCode problem is this?” and started asking: ✅ “Which pattern is hiding here?” everything changed. This cheat sheet covers the core DSA patterns that solve the majority of interview questions: • Two Pointers • Sliding Window • Prefix Sum • Binary Search • Fast & Slow Pointers • Monotonic Stack • Tree Traversal • Heap / Priority Queue • Top K Frequency • Merge Intervals • Hashmaps • DFS / BFS The biggest realization? The same pattern keeps showing up again and again in different forms. A “Longest Substring Without Repeating Characters” problem teaches you Sliding Window. A “Top K Frequent Elements” problem teaches you Heaps. A “Find Peak Element” problem teaches you Binary Search. A “Next Greater Element” problem teaches you Monotonic Stack. You don’t need to master 300 problems. You need to master the patterns. If I had to start over, I’d spend 7 days like this: Day 1: Arrays & Strings Day 2: Binary Search Day 3: Linked Lists Day 4: Stacks & Queues Day 5: Trees Day 6: Heaps / Priority Queues Day 7: Re-solve everything without notes That one week would be more valuable than months of random practice. #DataStructures #Algorithms #DSA #CodingInterview #LeetCode #SoftwareEngineering #Programming #InterviewPrep #ComputerScience #Tech
To view or add a comment, sign in
-
-
❌ Most people fail in DSA not because it's hard… But because they practice random questions without patterns. If you want to actually crack product-based companies, Master these 20 DSA patterns 👇 1. Two Pointers 2. Sliding Window 3. Fast & Slow Pointers (Cycle Detection) 4. Prefix Sum 5. Binary Search (on answer too) 6. Backtracking 7. Depth First Search (DFS) 8. Breadth First Search (BFS) 9. Topological Sort 10. Union Find (Disjoint Set) 11. Heap / Priority Queue 12. Greedy 13. Dynamic Programming (0/1 Knapsack, LIS, etc.) 14. Bit Manipulation 15. Monotonic Stack 16. Monotonic Queue 17. Trie (Prefix Tree) 18. Segment Tree / Fenwick Tree 19. Matrix Traversal (Spiral, BFS, DFS) 20. String Matching (KMP, Rabin-Karp) 💡 Reality check: You don’t need 1000 questions. You need pattern recognition + repetition. 👉 Solve 5–10 problems per pattern 👉 Revise regularly 👉 Focus on why the pattern works That’s how people go from “DSA is tough” → “DSA is predictable” Follow for more. #DSA #CodingInterview #SoftwareEngineering #LeetCode #Frontend #SDE #Programming
To view or add a comment, sign in
-
𝐃𝐏 𝐟𝐞𝐥𝐭 𝐢𝐦𝐩𝐨𝐬𝐬𝐢𝐛𝐥𝐞… 𝐮𝐧𝐭𝐢𝐥 𝐈 𝐚𝐩𝐩𝐫𝐨𝐚𝐜𝐡𝐞𝐝 𝐢𝐭 𝐭𝐡𝐞 𝐫𝐢𝐠𝐡𝐭 𝐰𝐚𝐲. 🚀 In my early DSA days, I used to fear Dynamic Programming. Every time I saw a DP problem, my mind went blank. No idea where to start, how to think, or what approach to follow. But the real problem wasn’t DP. It was my approach. Back to Basics 🔁 I went back to fundamentals. At one point, I was scared of recursion too. But when I actually spent time on it and practiced enough, recursion became my strongest and favorite part of DSA. That’s when things started changing. My DP Approach ⚡ One day, I decided to start DP seriously. No more random jumping — just a structured path: 1. Top-Down (Memoization) Start with recursion → store repeated results → avoid recomputation This is where I began, and honestly, still my favorite. 2. Bottom-Up (Tabulation) Convert recursion into iteration → build solutions step by step After memoization, I re-solved the same problems using this. 3. Space Optimization Once everything was clear, I focused on improving efficiency. What Worked for Me 📌 • Started with standard DP problems (with solutions available) • Solved all using memoization first • Re-solved using bottom-up • Finally optimized my solutions If you ask me my favorite — Memoization (Top-Down), always. Top 10 DP Problems to Start With 🧠 • Fibonacci Number • Climbing Stairs • House Robber • Coin Change • Longest Increasing Subsequence • 0/1 Knapsack • Longest Common Subsequence • Subset Sum • Minimum Path Sum • Edit Distance Final Thought 💡 DP is not hard. You just need the right entry point. Start with recursion — everything will start making sense.❤️ #DSA #DynamicProgramming #Coding #Programming #SoftwareEngineering #LearnToCode #CodingJourney #TechCareer #DeveloperLife #CodingLife
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