🚀 Day 10/100 – First Missing Positive | LeetCode (Hard) Double digits in my #100DaysOfChallenges journey! Today’s challenge was a classic interview problem that tests array manipulation + in-place hashing logic. 🧩 Problem: Given an unsorted integer array, return the smallest missing positive integer. Constraints: Must run in O(n) time Use O(1) extra space 🧠 Approach Used: Cyclic Sort (Index Placement Technique) Instead of using extra space like HashSet, I used an in-place strategy: ✔️ Place each number x at index x - 1 ✔️ Ignore negative numbers and numbers > n ✔️ Swap until every valid number is in its correct position ✔️ Scan the array to find the first index where nums[i] != i + 1 Core Idea: If 1 is at index 0, 2 at index 1, etc., The first mismatch gives the missing positive. 💡 Why This Is Smart: It uses the array itself as a hash structure No extra memory required Maintains linear time complexity ⏱ Complexity: Time: O(n) Space: O(1) 🎯 Key Learning: In-place hashing is powerful Hard problems often combine simple ideas cleverly Edge cases (negatives, duplicates, large values) matter a lot This problem strengthened my: 👉 Index mapping intuition 👉 Optimization mindset 👉 Confidence in solving Hard-level problems 90 days to go 🚀 #100DaysOfCode #LeetCode #DSA #Arrays #CyclicSort #Java #ProblemSolving #TechGrowth #AIML
LeetCode Hard Challenge: Smallest Missing Positive Integer
More Relevant Posts
-
Day 59 - LeetCode Journey Solved LeetCode 41: First Missing Positive (Hard) today — a problem that truly tests deep understanding of arrays, indexing, and optimization. This isn’t just about coding, it’s about thinking in-place, minimizing space, and using constraints smartly. 💡 Core Idea: Instead of using extra space, we treat the array itself as a hash map and place each element at its correct index (value → index mapping). This transforms the problem into finding the first index where the expected value is missing. ⚡ Approach Highlights: • Cyclic placement of elements to their correct positions • Ignoring invalid values (≤ 0 or > n) • Swapping until every valid number is at its right index • Final scan to find the first missing positive 🚀 Why this is powerful: • Achieves O(n) time complexity • Uses O(1) extra space • Demonstrates in-place hashing technique • Strengthens understanding of index manipulation patterns These are the kinds of problems that build real interview-level thinking — not just solving, but optimizing 💯 Every hard problem pushes boundaries a little further. Slow progress is still progress. ✅ Improved understanding of in-place algorithms ✅ Better optimization mindset ✅ Stronger grip on edge cases Still learning. Still improving. Still coding 🚀 #LeetCode #DSA #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #Algorithms #DataStructures #Arrays #Optimization #InterviewPreparation #KeepCoding #GrowthMindset
To view or add a comment, sign in
-
-
🚀 Day 2 of #100DaysOfDSA — Consistency in Action Today’s Problem: Product of Array Except Self (LeetCode 238) Difficulty: Medium At first glance, this problem looks simple… until you see the constraints 👀 ❌ Division is NOT allowed ⚡ Solution must run in O(n) time 🧠 Must handle zero values correctly 💡 Key Insight: Prefix + Suffix Product Technique Instead of calculating the product separately for each index (which would be slow), I learned how to precompute: ➡️ Product of elements to the LEFT of each index ➡️ Product of elements to the RIGHT of each index Then combine both to get the final answer. This approach reduces the complexity from O(n²) ➝ O(n) 🔥 📌 Example Input: [1, 2, 3, 4] Output: [24, 12, 8, 6] Each position contains the product of all elements except itself. 🎯 What I Learned Today ✅ How to avoid division using prefix & suffix arrays ✅ How to optimize space by reusing the output array ✅ Importance of thinking in terms of cumulative contributions ✅ A very common interview pattern for array problems 💭 Big Takeaway: Many “hard-looking” problems become simple once you think from both directions. Consistency > Motivation 💪 Day 2 Complete ✔️ On to Day 3 🔥 #100DaysOfDSA #LeetCode #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareEngineering #Java #Tech
To view or add a comment, sign in
-
-
Day 78 - LeetCode Journey Solved LeetCode 142: Linked List Cycle II (Medium) today — a powerful extension of the cycle detection problem. Earlier, we learned how to detect if a cycle exists. Now the challenge is to find the exact node where the cycle begins. 💡 Core Idea (Floyd’s Algorithm Extended): 1) Use slow & fast pointers to detect a cycle 2) Once they meet, reset one pointer to the head 3) Move both pointers one step at a time 4) The point where they meet again = start of the cycle 🤯 Why it works? Because of the mathematical relationship between distances traveled inside the cycle — both pointers align perfectly at the cycle entry point. ⚡ Key Learning Points: • Advanced use of two-pointer technique • Understanding the mathematics behind cycle detection • Solving without modifying the list • Maintaining O(n) time and O(1) space This is not just coding — this is algorithmic thinking at a deeper level. Also, this pattern connects with: -> Find duplicate number (cycle in array) -> Happy Number problem -> Loop detection in graphs ✅ Stronger conceptual clarity ✅ Better problem-solving depth ✅ Confidence with tricky pointer problems From detecting a cycle to pinpointing its start — that’s real progress 🚀 #LeetCode #DSA #Java #LinkedList #TwoPointers #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
🚀 A quick tip from the “Rotate String” problem! A popular trick to check if one string is a rotation of another is this: return s.length() == goal.length() && (s + s).contains(goal); The idea is pretty straightforward: if goal is a rotation of s, it’ll show up somewhere inside s + s. For example: s = "abcde" goal = "cdeab" s + s = "abcdeabcde" and you can see "cdeab" right there. But here’s the catch: the .contains() method does a substring search that can be slow in the worst case (up to O(n²)). So while this trick usually works fine, it’s not the most efficient for all cases. But to reduce the time complexity, we can use KMP (Knuth–Morris–Pratt) algorithm instead: Build the LPS (Longest Prefix Suffix) array for goal Use KMP to search for goal inside s + s This guarantees the search will run in O(n) time. 💡 It’s a good reminder that a simple trick can solve a problem quickly, but knowing classic algorithms like KMP helps to build solutions that perform well even in tricky situations. #Algorithms #Coding #TechTips #Java #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Day 61 - LeetCode Journey Solved LeetCode 81: Search in Rotated Sorted Array II (Medium) today — a problem that combines binary search + edge case handling + duplicates. This isn’t just a normal binary search. Here, the array is rotated and may contain duplicates, which makes the decision logic more subtle. 💡 Core Idea: At every step, determine which half is sorted. Then decide whether the target lies in that sorted half. If duplicates block the decision, carefully shrink the search space. ⚡ Key Learning Points: • Applying binary search on a rotated array • Handling duplicate values that break clear ordering • Smart boundary adjustments (low++, high--) • Maintaining efficiency close to O(log n) in most cases The real challenge was not writing the code — It was thinking clearly about all possible scenarios. Problems like this strengthen pattern recognition and deepen understanding of search-based algorithms 💯 ✅ Stronger grip on modified binary search ✅ Better handling of tricky edge cases ✅ Improved logical decision-making Each variation of binary search builds sharper intuition. Still learning. Still improving. Still coding 🚀 #LeetCode #DSA #Java #BinarySearch #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 81 - LeetCode Journey 🚀 Solved LeetCode 2: Add Two Numbers (Medium) — a classic linked list problem that beautifully combines arithmetic with pointer manipulation. At first, it looks like simple addition. But the twist is that numbers are stored in reverse order as linked lists, and we must simulate digit-by-digit addition. 💡 Core Idea (Simulation + Carry Handling): Traverse both linked lists simultaneously Add corresponding digits along with carry Create a new node for each digit of the result Move forward until both lists and carry are exhausted A dummy node helps in building the result list smoothly. 🤯 Why it works? Because we mimic the exact process of manual addition, handling carry at each step, ensuring correctness even when lengths differ. ⚡ Key Learning Points: • Converting real-world logic into code (digit addition) • Handling carry efficiently • Traversing two linked lists together • Using dummy node for clean construction • Managing different list lengths gracefully • Achieving O(max(n, m)) time and O(1) extra space This problem strengthens both logical thinking and linked list handling. Also, this pattern connects with: Add Binary Multiply Strings Linked List arithmetic problems Big integer calculations ✅ Better understanding of simulation problems ✅ Stronger pointer + arithmetic combination ✅ Improved handling of edge cases (carry, unequal lengths) From simple addition to linked list manipulation — this is where logic meets implementation 🚀 #LeetCode #DSA #Java #LinkedList #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 80 - LeetCode Journey 🚀 Solved LeetCode 876: Middle of the Linked List (Easy) — a classic problem that introduces one of the most powerful patterns in linked lists. At first, finding the middle seems straightforward. But doing it efficiently in a single pass is where the real insight comes in. 💡 Core Idea (Slow & Fast Pointer Technique): Initialize two pointers: slow and fast Move slow by 1 step and fast by 2 steps When fast reaches the end, slow will be at the middle If there are two middle nodes, this approach naturally returns the second one. 🤯 Why it works? Because the fast pointer covers double the distance of the slow pointer, so when it finishes traversing the list, the slow pointer is exactly halfway. ⚡ Key Learning Points: • Efficient single-pass traversal • Mastering the slow-fast pointer pattern • Handling even and odd length lists • Achieving O(n) time and O(1) space • Building intuition for pointer-based problems This is a foundational pattern used in many advanced problems. Also, this pattern connects with: Linked List Cycle detection Palindrome Linked List Reorder List Finding intersection of two linked lists ✅ Stronger grasp of two-pointer technique ✅ Better problem-solving efficiency ✅ Cleaner and optimized linked list logic Simple problem, powerful pattern — this is how concepts build up 🚀 #LeetCode #DSA #Java #LinkedList #TwoPointers #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 70 - LeetCode Journey Solved LeetCode 88: Merge Sorted Array (Easy) today — a classic problem that focuses on array manipulation and the two-pointer technique. The challenge is to merge two sorted arrays into one sorted array without using extra space, by modifying nums1 in-place. 💡 Core Idea: Instead of merging from the beginning, we start from the end of the arrays. Why? Because nums1 already has extra space at the end to accommodate elements from nums2. We use three pointers: • i → last valid element in nums1 • j → last element in nums2 • k → last position of merged array At each step, we place the larger element at position k, ensuring the array remains sorted. ⚡ Key Learning Points: • Using the two-pointer technique from the end • Performing in-place array merging • Maintaining O(m + n) time complexity • Avoiding unnecessary extra space This problem is a great reminder that sometimes changing the direction of traversal makes the solution much simpler. ✅ Better understanding of array manipulation ✅ Stronger grasp of two-pointer techniques ✅ Improved problem-solving efficiency Small problems like this build strong fundamentals for bigger challenges 🚀 #LeetCode #DSA #Java #TwoPointers #Arrays #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperGrowth #KeepCoding
To view or add a comment, sign in
-
-
Day 24 of my #50DaysOfCode challenge is done ✅ 📌 Problem Solved Convert Binary to Decimal We were given a binary number. Task was to convert it into decimal. Binary uses base 2. Decimal uses base 10. So the idea is simple. Each binary digit represents a power of 2. Example: Binary 1011 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11 💻 Brute Force Approach 🔹️Take the binary number as a string. 🔹️Start from the rightmost digit. 🔹️Maintain a base variable (starting from 1). 🔹️If the digit is '1', add base to result. 🔹️Multiply base by 2 after each step. 🔹️Continue till all digits are processed. Time Complexity: O(n) Space Complexity: O(1) 💻 Optimal Approach (Using Built-in Functions) Instead of manual conversion, we can use built-in functions. 🔹️Convert binary string directly to integer. 🔹️Specify base 2 during conversion. 🔹️Language handles the calculation internally. Time Complexity: O(n) Space Complexity: O(1) 📚 What I learned today: ▫️Binary numbers are just powers of 2. ▫️Right-to-left traversal helps in base calculations. ▫️Built-in functions can simplify many tasks. ▫️Understanding manual logic still matters for interviews. Day 24 completed. Bit manipulation basics getting clearer 🚀 #50DaysOfCode #CodingChallenge #Consistency #LearningInPublic
To view or add a comment, sign in
-
Day 66 - LeetCode Journey Solved LeetCode 167: Two Sum II – Input Array Is Sorted (Medium) today — a great example of how knowing the properties of a sorted array can drastically simplify the solution. Since the array is already sorted in non-decreasing order, we can avoid extra data structures and use a two-pointer approach to find the pair efficiently. 💡 Core Idea: Start with two pointers: • left at the beginning • right at the end Then check the sum of the two numbers: If the sum is equal to the target → solution found If the sum is less than the target → move the left pointer forward If the sum is greater than the target → move the right pointer backward This gradually narrows down the search space until the correct pair is found. ⚡ Key Learning Points: • Leveraging sorted array properties • Efficient use of the two-pointer technique • Reducing time complexity to O(n) • Solving the problem with O(1) extra space Problems like this highlight how choosing the right technique can make solutions clean, fast, and elegant. ✅ Stronger understanding of two-pointer patterns ✅ Better optimization mindset ✅ Improved problem-solving intuition Every problem solved adds another useful pattern to the toolkit 🚀 #LeetCode #DSA #Java #TwoPointers #Algorithms #ProblemSolving #CodingJourney #Consistency #100DaysOfCode #InterviewPreparation #DeveloperJourney #KeepCoding
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