🔥 Day 115 of My DSA Challenge – Intersection of Two Arrays II 🔷 Problem : 350. Intersection of Two Arrays II 🔷 Goal : Return the intersection of two arrays, where each element in the result must appear as many times as it shows in both arrays. Order doesn’t matter. 🔷 Key Insight : This is an extension of the previous problem (Intersection of Two Arrays). The twist? Here we need to consider duplicate occurrences too. For example : nums1 = [1,2,2,1], nums2 = [2,2] → result should be [2,2] (because 2 appears twice in both). 🔷 Approach : 1️⃣ Use a HashMap to count occurrences of each element in nums1. 2️⃣ Traverse nums2 and check if an element exists in the map. 3️⃣ If yes → add it to the result and decrease its count in the map. 4️⃣ When the count becomes 0, remove it from the map to keep things clean. Time Complexity: O(n + m) Space Complexity: O(n) This problem strengthens hash-based frequency counting and element tracking. Use a map to record frequency — then match, decrease, and clean up. This logic is key for : ✅ Counting duplicates ✅ Array frequency comparison ✅ Inventory & matching systems Every small concept compounds into bigger problem-solving clarity. Step by step, I’m becoming stronger at thinking like a coder 💪💻 #Day115 #DSA #100DaysOfCode #HashMap #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #LogicBuilding #EngineerMindset #GrowEveryday
"Day 115 of DSA Challenge: Intersection of Two Arrays II with HashMap"
More Relevant Posts
-
💡 Day 114 of My DSA Challenge – Intersection of Two Arrays 🔷 Problem : 349. Intersection of Two Arrays 🔷 Goal : Find the unique common elements between two integer arrays. The order of elements doesn’t matter. 🔷 Key Insight : This is a Hashing-based problem. We need to identify the numbers that appear in both arrays — but each element should appear only once in the result. The idea is simple : 1️⃣ Store all elements of the first array in a HashMap (or HashSet). 2️⃣ Traverse the second array and check for matches. 3️⃣ Whenever a match is found → add it to the result and remove it to avoid duplicates. 🔷 Approach : 1️⃣ Use a HashMap to store unique elements from nums1. 2️⃣ Iterate through nums2, and if an element exists in the map → add it to the result list. 3️⃣ Remove the element from the map after adding (to prevent duplicates). 4️⃣ Convert the result list to an array and return it. Time Complexity: O(n + m) Space Complexity: O(n) 🔷 Takeaway : This problem strengthens hash-based searching and uniqueness handling — Use HashMap / HashSet when you need fast lookups and uniqueness control. ✅ This logic is frequently used in : Duplicate removal problems Union & intersection operations Set theory-based DSA problems ✨ Another simple yet powerful concept mastered. Every small step counts toward building a strong foundation. 💪 #Day114 #DSA #100DaysOfCode #HashMap #HashSet #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #LogicBuilding #EngineerMindset
To view or add a comment, sign in
-
-
🔥 Day 118 of My DSA Challenge – Sort Array By Parity II 🔷 Problem : 922. Sort Array By Parity II 🔷 Goal : Rearrange the array so that — ✅ At even indices, we place even numbers ✅ At odd indices, we place odd numbers Given condition : Half of the numbers are even, half are odd — so a valid arrangement is always possible. 🔷 Key Insight : This problem is a perfect example of pointer-based placement. We don’t need to sort — we just need to place: Even numbers → even positions Odd numbers → odd positions We can do this in one pass by using two pointers: evenP → starts at index 0 oddP → starts at index 1 Whenever we find an even number → place it at evenP, move evenP += 2 Whenever we find an odd number → place it at oddP, move oddP += 2 🔷Approach : 1️⃣ Create a result array res of the same size 2️⃣ Track even and odd positions using two pointers 3️⃣ Traverse the array once 4️⃣ Place each number at the correct index (even or odd) 5️⃣ Return the result array Time Complexity: O(n) Space Complexity: O(n) This problem helps build intuition for index-based placement and parity logic. Place elements where they belong — efficient, simple, and clean ✅ This pattern is useful in : ✅ Rearrangement problems ✅ Partitioning by conditions ✅ Two-pointer placement algorithms Every new problem improves how I think about arrays and patterns. Step-by-step progress, every single day 🔥 #Day118 #DSA #100DaysOfCode #LeetCode #Java #Arrays #TwoPointers #ProblemSolving #CodingJourney #Algorithms #DataStructures #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
🔥 Day 116 of My DSA Challenge – Move Zeroes 🔷 Problem : 283. Move Zeroes 🔷 Goal : Move all 0s to the end of the array while maintaining the relative order of non-zero elements. Must be done in-place without using extra space. 🔷 Key Insight : This problem focuses on in-place array manipulation and pointer logic. We need to keep all non-zero elements in front and shift all zeros toward the end — but without disturbing their relative order. A simple and efficient solution is to use the two-pointer approach: One pointer (idx) scans through the array. Another pointer (k) keeps track of where the next non-zero should be placed. 🔷 Approach : 1️⃣ Initialize pointer k = 0 2️⃣ Traverse the array with index idx 3️⃣ If nums[idx] != 0, assign nums[k] = nums[idx] If k != idx, set nums[idx] = 0 to push zero backward Increment k 4️⃣ The array is now rearranged in-place Time Complexity: O(n) Space Complexity: O(1) This problem strengthens array manipulation and in-place optimization skills. Use pointers wisely — move only what’s needed, keep it clean, keep it fast. This logic is useful for : ✅ Partitioning problems ✅ Rearranging arrays ✅ In-place sorting optimizations Another small but meaningful win — one step closer to mastering the art of clean, efficient code 🚀 #Day116 #DSA #100DaysOfCode #LeetCode #TwoPointers #Arrays #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney #EngineerMindset #LogicBuilding #GrowEveryday
To view or add a comment, sign in
-
-
🔥 Day 117 of My DSA Challenge – Partition Array According to Given Pivot 🔷 Problem : 2161. Partition Array According to Given Pivot 🔷 Level : Medium 🔷 Goal : Rearrange an array so that — 1️⃣ Elements less than the pivot come first 2️⃣ Elements equal to the pivot come next 3️⃣ Elements greater than the pivot come last …and maintain relative order for smaller and larger elements. 🔷 Key Idea : The problem is a great test of array manipulation and partitioning logic — similar to what we see in the partition step of quicksort, but here the order must be stable (unchanged for equal categories). We can solve it cleanly using extra space and multiple passes: First collect elements < pivot Then elements == pivot Finally elements > pivot 🔷 Approach : 1️⃣ Initialize a result array res of same size. 2️⃣ Keep two pointers — left starts from the beginning for smaller elements. right starts from the end for larger elements. 3️⃣ Fill smaller elements from the start. 4️⃣ Fill larger elements from the end (in reverse order). 5️⃣ Fill the middle portion with the pivot. Time Complexity: O(n) Space Complexity: O(n) This problem strengthens your understanding of partitioning logic, stable ordering, and array construction — all fundamental to sorting algorithms and data arrangement. Small rearrangements. Big insights. Every element has its right place — in arrays and in life. ⚡ #Day117 #DSA #100DaysOfCode #LeetCode #Java #Arrays #ProblemSolving #CodingChallenge #Algorithms #DataStructures #LearningJourney #CodeEveryday #DeveloperMindset #EngineerInProgress
To view or add a comment, sign in
-
-
🔥 Day 109 of My DSA Challenge – Intersection of Two Arrays 🔷 Problem : 349. Intersection of Two Arrays 🔷 Goal : Return the unique intersection of two integer arrays. Order doesn’t matter, but duplicates should not appear in the result. 🔷 Key Insight : This is a set / hashmap based lookup problem. We store elements from the first array, then check if elements from the second array exist in it. To ensure uniqueness, we remove the element once counted, so duplicates don't appear. 🔷 Approach : 1️⃣ Add all elements of nums1 to a HashMap 2️⃣ Traverse nums2 3️⃣ If the element exists in the map → add to result & remove from map 4️⃣ Convert list to array and return Time Complexity: O(n + m) Space Complexity: O(n) Sometimes the simplest tools — like HashMaps/Sets — give the cleanest solutions. Learning to choose the right data structure = faster logic + cleaner code 💪 #Day109 #100DaysOfCode #LeetCode #DSA #Java #HashMap #DataStructures #CodingChallenge #Algorithm #ProblemSolving #Programming #SoftwareEngineering #TechJourney #DeveloperJourney #CodeEveryday #LearnDSA #LogicBuilding #GrowthMindset #EngineerMindset
To view or add a comment, sign in
-
🔥 Day 121 of My DSA Challenge – Remove Duplicates from Sorted List 🔷 Problem : 83. Remove Duplicates from Sorted List 🔷 Goal : Given the head of a sorted linked list, remove all duplicate nodes so that each element appears only once, while maintaining the sorted order. 🔷 Key Insight : This problem is a great example of linked list traversal and pointer management. Because the list is already sorted, all duplicates appear consecutively — which makes it easy to detect and skip them in one pass. The challenge is to handle links carefully so that only unique nodes remain connected. 🔷 Approach : 1️⃣ Initialize a dummy node (with a distinct value) to simplify linking. 2️⃣ Use a tail pointer to build a new list containing only unique elements. 3️⃣ Traverse the list using head: If head.val is not equal to the last added node (tail.val), link it. Otherwise, skip the duplicate. 4️⃣ Update tail.next = null at the end to avoid leftover links. 5️⃣ Return dummy.next as the new head. Time Complexity: O(n) Space Complexity: O(1) This problem strengthens concepts of : ✅ Duplicate handling in linked lists ✅ Pointer-based traversal ✅ Clean in-place modification Sometimes, cleaning a data structure is just about connecting only what truly matters. ⚡ Every small pattern makes a big difference in problem-solving clarity. One more concept locked in 💻 #Day121 #DSA #100DaysOfCode #LeetCode #Java #LinkedList #ProblemSolving #Algorithms #DataStructures #CodingChallenge #DeveloperJourney #EngineerMindset #GrowEveryday
To view or add a comment, sign in
-
-
🚀 Day 91 of #SridharSolves100 – “Check If Digits Are Equal in String After Operations I” 💡 Problem Insight: Given a numeric string s, we repeatedly replace it with a sequence of sums of consecutive digits modulo 10 — until only two digits remain. If the final two digits are the same, return true; otherwise, false. ✅ Digits are equal → true 💭 Intuition: Think of it like compressing a signal waveform — each reduction step combines adjacent elements until we reach a minimal “frequency signature.” If the last two digits resonate (are equal), the signal stabilizes — otherwise, it diverges. ⚙️ Approach: ==> Convert the string to a list of digits. While length > 2: Replace the list with consecutive (a+b)%10 results. Return true if final digits are equal, else false. 💻 Time Complexity: O(n²) (since each iteration reduces size by 1) 💾 Space Complexity: O(n) 🎯 Real-World Analogy: This is like data aggregation in sensor networks — multiple readings are merged iteratively to reach a single consensus. If the consensus stays stable (equal digits), it indicates consistency; if not, there’s fluctuation (difference in data pattern). 🔗 My Solution: https://shorturl.at/TSRlq 👉 Pro tip: Always watch for “repeated operation until condition” patterns — they hide simulation loops that can be optimized or simplified using math observation. #Java #DataStructures #CodingInterview #Algorithm #StringManipulation #Simulation #ProblemSolving #GreedyApproach #PrefixSum #100DaysOfCode #SridharSolves100 #TechCareer #DSA #LeetCode #CodingChallenge
To view or add a comment, sign in
-
-
🔥 Day 36/100 of #100DaysOfCode - Matrix Zero Transformation! Today's Problem: Set Matrix Zeroes Task: Given an m x n matrix, if an element is 0, set its entire row and column to 0s. Must be done in-place. Solution: Used the optimal O(1) space approach! Leveraged the first row and first column as markers to track which rows/columns need to be zeroed, with a separate variable for column 0. Key Steps: Mark zeros in first row/column while preserving original state Process inner matrix using the markers Zero rows/columns based on markers Smart Optimizations: Uses matrix itself for storage instead of extra O(m+n) space Handles edge case for first column separately Single pass for marking + two passes for execution Advanced matrix manipulation that demonstrates deep understanding of in-place algorithms! Perfect example of trading complexity for optimal space usage. 🧩 #100DaysOfCode #LeetCode #Java #Algorithms #Matrix #InPlace #CodingInterview
To view or add a comment, sign in
-
-
Data Structure and Algorithms Merge Two Sorted Lists For my lab assignment, I solved the LeetCode problem “Merge Two Sorted Lists” using C++ linked lists and pointer manipulation. 🔹 Approach I Used: I compared the starting nodes of both lists, picked the smaller one as the head, and then iteratively attached the next smallest nodes using a pointer (curr). When one list ended, I simply linked the remaining nodes of the other list to complete the merge efficiently. 🔹 Key Concepts: Linked Lists Pointer updates Iterative merging Time Complexity: O(n + m) This assignment really helped me improve my understanding of linked list traversal and handling edge cases. 🎥 Video Explanation: [https://lnkd.in/df6nZs3w] Note: At first I thought merging lists would merge me instead but thankfully only the code struggled, not me! #DSA #LabAssignment #LeetCode #C++ #CodingPractice #ProblemSolving #MergeTwoSortedLists
To view or add a comment, sign in
-
Data Structure and Algorithms Merge Two Sorted Lists. For my lab assignment, I solved the LeetCode problem “Merge Two Sorted Lists” using C++ linked lists and pointer manipulation. 🔹 Approach I Used: I compared the starting nodes of both lists, picked the smaller one as the head, and then iteratively attached the next smallest nodes using a pointer (curr). When one list ended, I simply linked the remaining nodes of the other list to complete the merge efficiently. 🔹 Key Concepts: Linked Lists Pointer updates Iterative merging Time Complexity: O(n + m) This assignment really helped me improve my understanding of linked list traversal and handling edge cases. 🎥 Video Explanation: [https://lnkd.in/df6nZs3w] Note: At first I thought merging lists would merge me instead—but thankfully only the code struggled, not me! #DSA #LabAssignment #LeetCode #C++ #CodingPractice #ProblemSolving #MergeTwoSortedLists
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