"Day 115 of DSA Challenge: Intersection of Two Arrays II with HashMap"

🔥 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

  • graphical user interface

To view or add a comment, sign in

Explore content categories