🚀 Day 12/30 – Mastering Binary Search Patterns Today’s problem required finding the position of a target value in a sorted array — or determining where it should be inserted if it doesn’t exist. Rather than scanning linearly, I implemented a Binary Search approach to maintain optimal performance. 💡 Approach Maintain two pointers: left and right Compute mid carefully to avoid overflow Compare the target with the middle element Narrow the search space accordingly If the element is not found, return the left pointer as the insertion index This pattern ensures: ⏱ O(log n) time complexity 📦 O(1) space complexity 📊 Performance ✅ All test cases passed ⚡ 0 ms runtime (100% performance) 💾 Strong memory efficiency 📚 Key Takeaway Binary Search is more than just finding elements — it’s about identifying boundaries and understanding how search space evolves. Recognizing insertion logic as a natural extension of search strengthens problem-solving intuition. Day 12 complete. The fundamentals are getting sharper every day. #Day12 #30DaysOfCode #LeetCode #Java #BinarySearch #Algorithms #ProblemSolving #SoftwareEngineering #CodingJourney #Consistency #TechGrowth
Mastering Binary Search with Java
More Relevant Posts
-
🚀 Day 13/100 — Recursive Deconstruction Today’s Challenge: LeetCode 761 - Special Binary String 🧩 Yesterday was about bits; today was about Structural Grammar. Special Binary Strings aren't just 1s and 0s; they are a language. The Realization: A special string is like a valid set of parentheses. 1 is ( and 0 is ). To find the "lexicographically largest" version, you have to break the string into its most basic components, sort them, and put them back together. My 0ms Optimization Strategy: 1. Mental Mapping: Treated the string as a nested structure. If 1...0 is a special string, I stripped the outer layer, solved the inside, and then re-wrapped it. 2. Greedy Reassembly: Used Collections.sort() with a reverse comparator. In binary, "larger" just means the 1s appear as early as possible. 3. Memory Management: Minimized object creation by identifying "split points" first before committing to substring allocations. Reflection: Sometimes the fastest way to solve a problem isn't to iterate forward, but to look at the problem as a recursive tree. Every "Special" chunk is a node that can be reordered to maximize the total value. 13 days down. The logic is getting deeper. 87 days to go. 🛠️ #Java #DSA #LeetCode #100DaysOfCode #Recursion #StringAlgorithms #SoftwareEngineer #CodingJourney #Optimization
To view or add a comment, sign in
-
-
🚀 Day 13/30 – Tracking Patterns in Arrays Today’s problem focused on finding the maximum number of consecutive 1’s in a binary array. While the logic is straightforward, the key is identifying and tracking streaks efficiently without using extra space. 💡 Approach Traverse the array once Maintain a running counter for consecutive 1’s Reset the counter when a 0 is encountered Continuously track the maximum streak using Math.max() This ensures: ⏱ O(n) time complexity 📦 O(1) space complexity 📊 Performance ✅ All test cases passed ⚡ Efficient runtime 💾 Constant space usage 📚 Key Takeaway Problems like this reinforce an important idea: Many array questions are about recognizing patterns and maintaining state correctly during traversal. Even simple problems sharpen attention to iteration logic and edge handling. Day 13 complete. Consistency + clarity = steady improvement. #Day13 #30DaysOfCode #LeetCode #Java #Algorithms #ArrayProblems #ProblemSolving #SoftwareEngineering #CodingJourney #Consistency #TechGrowth
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟴/𝟭𝟬𝟬 | 𝗖𝗼𝗻𝘃𝗲𝗿𝘁 𝗕𝗶𝗻𝗮𝗿𝘆 𝗡𝘂𝗺𝗯𝗲𝗿 𝗶𝗻 𝗔 𝗟𝗶𝗻𝗸𝗲𝗱 𝗟𝗶𝘀𝘁 𝘁𝗼 𝗜𝗻𝘁𝗲𝗴𝗲𝗿 Day 48 ✅ — Binary logic meets linked list traversal. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟭𝟮𝟵𝟬: Convert Binary Number in a Linked List to Integer (Easy) From LeetCode 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Each node represents a binary digit (0 or 1). The head is the most significant bit. So this isn’t just a linked list problem — it’s a 𝗯𝗶𝗻𝗮𝗿𝘆 𝘁𝗼 𝗱𝗲𝗰𝗶𝗺𝗮𝗹 𝗰𝗼𝗻𝘃𝗲𝗿𝘀𝗶𝗼𝗻 problem wrapped inside linked list traversal. Two key steps: 1️⃣ Compute the length of the list 2️⃣ Traverse again and apply positional binary weights (2^(length-1)) If a node contains 1, add 2^(position) to the result. Classic bit-weight logic. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 First pass: calculate linked list length 👉 Second pass: • If node value is 1 → add 2^(length-1) • Decrement length 👉 Handle last node separately Time Complexity: O(n) Space Complexity: O(1) Two traversals, constant space, clean logic. 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: This problem reinforces something important: Linked list questions aren’t always about pointer manipulation. Sometimes they test whether you can layer fundamental concepts (like binary math) on top of traversal mechanics. The more I practice, the clearer patterns become: Traversal is routine. The real thinking is in identifying the hidden concept. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/g9TyHZGk 𝗗𝗮𝘆 𝟰𝟴/𝟭𝟬𝟬 ✅ | 𝟱𝟮 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #Binary #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #TimeComplexity #Programming
To view or add a comment, sign in
-
𝗗𝗮𝘆 𝟱𝟳/𝟭𝟬𝟬 — 𝗪𝗵𝗲𝗻 𝗦𝘁𝗮𝗰𝗸𝘀 𝗚𝗲𝘁 𝗚𝗿𝗲𝗲𝗱𝘆 Yesterday: Valid Parentheses. Basic stack. Today: Remove Duplicate Letters. Stack + greedy + frequency tracking. Level up. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ #𝟯𝟭𝟲: Remove Duplicate Letters (Medium) 𝗧𝗵𝗲 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲: Remove duplicate letters so the result is: Smallest in lexicographical order (dictionary order) Contains each letter exactly once Example: "bcabc" → "abc" The trick? Knowing when to remove a character from the stack to make room for a better one. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: Monotonic stack + greedy decisions. 👉 Track frequency: how many times each character appears ahead 👉 Track visited: have we already used this character? 👉 For each character, pop stack if: Stack top is larger (worse for lexicographical order) Stack top appears again later (we can use it then) 👉 Push current character and mark visited Time: O(n), Space: O(1) — only 26 letters max. 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: This combines three patterns: Monotonic stack (maintaining order) Greedy algorithm (making locally optimal choices) Frequency tracking (knowing what's ahead) Solving it wasn't about knowing one technique. It was about combining them. 𝗖𝗼𝗱𝗲: https://lnkd.in/gzw6ACFr 57 down. 43 to go. 𝗗𝗮𝘆 𝟱𝟳/𝟭𝟬𝟬 ✅ #100DaysOfCode #LeetCode #Stack #MonotonicStack #GreedyAlgorithm #DataStructures #Algorithms #CodingInterview #Programming #Java #MediumLevel #PatternCombination
To view or add a comment, sign in
-
📌 17. Letter Combinations of a Phone Number (Medium) Today’s problem was all about Backtracking & Recursion. 🧠 Problem Summary Given digits from 2–9, return all possible letter combinations based on phone keypad mapping. Example: Input: "23" Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"] 💡 Key Insight This is a classic Cartesian Product problem. Each digit expands into multiple choices → Perfect use case for Backtracking. 🚀 Approach Create a digit → letter mapping Use recursion to build combinations When current string length == digits length → Add to result Backtrack and explore next possibilities ⏱ Complexity Time: O(4ⁿ) Space: O(n) recursion stack Max combinations = 256 (since n ≤ 4) 🎯 What I Practiced Today ✅ Recursion Tree Thinking ✅ Backtracking Pattern ✅ StringBuilder Optimization ✅ Clean Code Structure Consistency > Motivation 💪 Day 18 completed. #LeetCode #Java #DataStructures #Algorithms #Backtracking #100DaysOfCode
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 | 𝗗𝗲𝗹𝗲𝘁𝗲 𝗡𝗼𝗱𝗲 & 𝗥𝗲𝗺𝗼𝘃𝗲 𝗘𝗹𝗲𝗺𝗲𝗻𝘁𝘀 Day 44 ✅ — Two deletion techniques, one day. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺𝘀: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟯𝟳: Delete Node in a Linked List (Medium) ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟮𝟬𝟯: Remove Linked List Elements (Easy) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: 𝕯𝖊𝖑𝖊𝖙𝖊 𝕹𝖔𝖉𝖊 (#237): The twist? You're only given the node to delete—not the head. Can't access previous node. Solution: Copy next node's value to current, then skip next. Clever trick that feels like breaking the rules. 𝕽𝖊𝖒𝖔𝖛𝖊 𝕰𝖑𝖊𝖒𝖊𝖓𝖙𝖘 (#203): Remove all nodes with a specific value. The standard deletion problem—handle head separately, then traverse and skip matching nodes. Two problems, two deletion strategies. Both are in-place, O(1) space. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵𝗲𝘀: 𝑫𝒆𝒍𝒆𝒕𝒆 𝑵𝒐𝒅𝒆: 👉 Copy next node's value to current 👉 Skip next node: node.next = node.next.next 𝑹𝒆𝒎𝒐𝒗𝒆 𝑬𝒍𝒆𝒎𝒆𝒏𝒕𝒔: 👉 Handle head nodes with target value first 👉 Traverse and skip nodes matching value 👉 Return potentially new head Time: O(n), Space: O(1) for both 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Fifteen linked list problems (Day 30-44). Deletion patterns are now second nature. The "Delete Node" trick shows that sometimes the clever solution isn't what you'd expect. Challenge your assumptions. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gMb9bPNy 𝗗𝗮𝘆 𝟰𝟰/𝟭𝟬𝟬 ✅ | 𝟱𝟲 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #NodeDeletion #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #InPlaceAlgorithm #Programming #ProblemSolving
To view or add a comment, sign in
-
Headline: Cracking the "Largest Rectangle in Histogram" (LeetCode 84) 🚀 I just cleared this classic Hard problem with a 0ms runtime! The challenge is finding the largest area in a histogram in O(n) time. The secret sauce? A Monotonic Stack. By storing indices of bars in increasing order, we can identify the "boundary" for each height in a single pass. Key takeaway: Choosing the right data structure (like a Stack) can turn an expensive O(n^2) search into a lightning-fast linear solution. 👨💻 #LeetCode #Java #Algorithms #DataStructures #CodingLife
To view or add a comment, sign in
-
-
🚀 24/02/26 — From Rotations to Root Nodes: Today’s DSA Wins Today I tackled some clever problems that pushed me to think differently about strings and trees. Here’s a quick breakdown of what I learned and implemented: 🔄 Strobogrammatic Numbers — LeetCode 246 A number that looks the same when rotated 180° (like "69" or "88"). Approach: Used a Two-Pointer technique with a rotation map including '0', '1', '8', '6', and '9'. Complexity: O(N) Time and O(1) Space. Result: 100% runtime beats (0ms). 🧵 Append Characters to Make Subsequence — LeetCode 2486 Goal: Find the minimum characters to append so that string t becomes a subsequence of string s. Approach: Applied a Greedy Two-Pointer strategy to match characters while traversing both strings. Complexity: O(N + M) Time and O(1) Space. 🌳 LCA of Binary Tree III — LeetCode 1650 Nodes have parent pointers, which made this problem fascinating. I implemented two approaches: Approach 1 — HashSet Ancestor Tracking: Store all ancestors of node p in a HashSet, then check node q’s ancestors against it. Efficiency: O(N) Time , O(N) Space. 🚀 Approach 2 — Linked List Intersection Trick: Treat paths to the root as two intersecting linked lists. Redirect pointers when reaching null so they meet at the Lowest Common Ancestor. Efficiency: O(N) Time , O(1) Space. 💡 Lightbulb Moment Realizing that the Intersection of Two Linked Lists pattern works perfectly for trees with parent pointers was a game-changer. Today was proof that pattern mastery > memorizing problems. Thanks to Anuj Kumar (a.k.a CTO Bhaiya on YouTube) for the guidance and high-quality resources that keep me learning. Visual notes + 100% runtime screenshots attached below! 📄👇 #DSA #Java #LeetCode #CodingJourney #TwoPointers #BinaryTree #Optimization #LearningInPublic #CTOBhaiya
To view or add a comment, sign in
-
Day 72/100 – LeetCode Challenge ✅ Problem: #7 Reverse Integer Difficulty: Medium Language: Java Approach: Digit Extraction with Overflow Check Time Complexity: O(log₁₀ x) Space Complexity: O(1) Key Insight: Reverse integer by repeatedly extracting last digit and building result. Critical: Check overflow before final cast using long to detect > Integer.MAX_VALUE or < Integer.MIN_VALUE. Solution Brief: Extracted digits using modulo 10. Built reversed number step by step in long to detect overflow. After loop, divided by 10 to remove extra multiplication. Checked if result fits in 32-bit integer range. Handled sign separately at the end. #LeetCode #Day72 #100DaysOfCode #Math #Java #Algorithm #CodingChallenge #ProblemSolving #ReverseInteger #MediumProblem #Overflow #DigitManipulation #DSA
To view or add a comment, sign in
-
-
🚀 Day 63/100 – #LeetCodeChallenge 📌 Problem: Count Binary Substrings Today’s problem was all about spotting patterns in binary strings — and it turned out to be a fun exercise in run-length encoding logic! 🧠 🔍 Approach: Instead of storing counts separately, I used a simple linear scan to keep track of consecutive identical characters (strk) and the length of the previous run (prev). Whenever a run ends, we update prev and reset strk. Then, if the current streak is ≤ the previous one, it means we’ve found a valid substring — and we increment the result. 📈 ⚡ Result: ✅ Runtime: 10 ms – beats 87.50% 🚀 💾 Memory: 46.44 MB – beats 56.68% Feeling good about the balance between time and space efficiency here! Every day is a step closer to mastering problem-solving patterns. 💪 🔗 Takeaway: Sometimes the most elegant solutions come from simple observation — no need for complex data structures when a single pass and a few variables do the trick! #100DaysOfCode #LeetCode #Java #CodingChallenge #ProblemSolving #TechJourney #DevCommunity #StringManipulation #Algorithms #CodeNewbie #SoftwareEngineering #WomenInTech #CodingLife #InterviewPrep #DataStructures #DailyCoding
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