🔥 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
"Day 109 of DSA Challenge: Intersection of Two Arrays with HashMap"
More Relevant Posts
-
🚀 Day 406 of #500DaysOfCode 🎯 Problem: 3318. Find X-Sum of All K-Long Subarrays I 🧩 Difficulty: Easy Today’s challenge focused on computing the X-Sum for every subarray of length k. The X-Sum involves identifying the top X most frequent elements in each subarray — and if frequencies tie, we prioritize larger values. Then, we sum up the occurrences of only those selected elements 💡 💻 Approach: For each subarray of length k, count the frequency of elements. Sort elements by frequency (descending) and value (descending). Pick the top x elements and sum their occurrences in the subarray. Store this result for each subarray. 🧠 Key Concepts Used: Frequency counting using HashMap Custom sorting with comparator logic Sliding subarray analysis 📊 Complexity: O(n × k × log k) 🔍 Topics: Arrays | HashMap | Sorting Every problem solved adds a new pattern to how we think about optimization and logical structuring in code 💪 #Java #LeetCode #ProblemSolving #CodingChallenge #DataStructures #Algorithms #100DaysOfCode #500DaysOfCode
To view or add a comment, sign in
-
-
Day 71/160 — Detect Loop in Linked List 🔁 Today’s challenge was about finding cycles in a linked list — a classic problem that teaches how to spot infinite loops in data structures. 💡 Approach: Used Floyd’s Cycle Detection Algorithm (Tortoise & Hare) — Move one pointer one step at a time and another two steps. If they ever meet, there’s a loop! ⚙️ Complexity: O(n) time | O(1) space Slow and steady meets fast and furious 🐢🐇 — and the loop is caught! #Day71 #160DaysOfChallenge #DSA #Coding #LinkedList #Algorithms #Java #FloydCycleDetection #LearnToCode
To view or add a comment, sign in
-
-
Day 55 of My DSA Challenge Problem: Count the number of triplets in an array that can form a valid triangle. Concept Recap: For any three sides to form a triangle, the sum of any two sides must be greater than the third side. Optimized Approach: Instead of checking every triplet (which takes O(N³)), I sorted the array and used a two-pointer technique to bring it down to O(N²): Sort the array. Fix the largest side (arr[k]) and use two pointers (i, j) to find pairs where arr[i] + arr[j] > arr[k]. If the condition holds, all elements between i and j can form valid triangles. Count and move pointers accordingly. Time Complexity: O(N²) Space Complexity: O(1) Takeaway: Sorting combined with the two-pointer approach often transforms brute-force solutions into elegant and efficient ones. #Day55 #DSAChallenge #TwoPointerTechnique #Sorting #Optimization #Java #ProblemSolving #DataStructures #Algorithms #CodingChallenge #GeeksforGeeks #LeetCode #100DaysOfCode #ProgrammersJourney #TechLearning
To view or add a comment, sign in
-
-
🔥 Day 108 of My DSA Challenge – Merge Sorted Array 🔷 Problem : 88. Merge Sorted Array 🔷 Goal : Merge two sorted arrays into one sorted array in-place inside nums1. The tricky part? nums1 already has extra space at the end — and we need to fill it without using extra arrays. 🔷 Key Insight : Use the two-pointer technique starting from the end — this avoids overwriting values in nums1. Pointer p1 → end of valid elements in nums1 Pointer p2 → end of nums2 Pointer idx → last index in final merged array Place the largest element first by comparing from the end. 🔷 Approach : 1️⃣ Start from the last elements of both arrays 2️⃣ Compare and place the greater one at the end 3️⃣ Move pointers backwards 4️⃣ If nums2 still has elements, copy them This gives us O(m + n) time and O(1) extra space ✅ Sometimes the most elegant solutions are not about building new structures but smartly reusing what you already have. Two-pointer technique continues to be a powerful tool in array problems 💪 #Day108 #100DaysOfCode #LeetCode #DSA #Java #TwoPointers #Arrays #CodingChallenge #Algorithm #InPlaceAlgorithms #ProblemSolving #Programming #SoftwareEngineering #TechJourney #DeveloperJourney #CodeEveryday #LearnDSA #GrowthMindset #EngineerMindset #LogicBuilding
To view or add a comment, sign in
-
-
💡 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 407 of #365DaysOfCode 🎯 Problem: 3321. Find X-Sum of All K-Long Subarrays II 🧩 Difficulty: Hard Today’s challenge took the concept of frequency-based subarray analysis to the next level 🔥 Given an array and two integers k and x, the goal is to compute the X-Sum for every subarray of length k. The X-Sum is calculated by taking the sum of occurrences of the top X most frequent elements in the subarray (with ties broken by larger element value). 💡 Key Idea: Since n can go up to 10⁵, we can’t recompute everything for each subarray. We use a sliding window approach with a HashMap for frequency tracking — efficiently adding and removing elements as the window moves — and compute the X-Sum dynamically. 💻 Approach: 1️⃣ Maintain frequency counts using a HashMap. 2️⃣ Sort by frequency (and value when tied). 3️⃣ Use a sliding window to efficiently update counts instead of recalculating each time. 4️⃣ Compute and store the X-Sum for each window. 📊 Complexity: O(n × log(k)) 🧠 Concepts Used: Sliding Window | HashMap | Greedy Sorting Every hard problem is a reminder that optimization isn’t just about speed — it’s about thinking smart and coding cleaner. 💪 #LeetCode #Java #ProblemSolving #CodingChallenge #Algorithms #DataStructures #100DaysOfCode #365DaysOfCode #SlidingWindow #HashMap
To view or add a comment, sign in
-
-
💻 Day 62 of #LeetCode100DaysChallenge Solved LeetCode 142: Linked List Cycle II — a problem that deepens understanding of linked list traversal and cycle detection using pointers. 🧩 Problem: Given the head of a linked list, return the node where the cycle begins. If there’s no cycle, return null. A cycle exists if a node can be revisited by continuously following the next pointer. The goal is to identify the exact node where the cycle starts — without modifying the list. 💡 Approach — Floyd’s Cycle Detection (Tortoise and Hare): 1️⃣ Use two pointers — slow and fast. 2️⃣ Move slow by 1 step and fast by 2 steps until they meet (if a cycle exists). 3️⃣ Once they meet, reset one pointer to the head. 4️⃣ Move both one step at a time; the node where they meet again is the start of the cycle. 5️⃣ If no meeting point (i.e., fast or fast.next becomes null), return null. ⚙️ Complexity: Time: O(N) — each pointer traverses the list at most twice. Space: O(1) — no extra memory used. ✨ Key Takeaways: ✅ Strengthened Floyd’s algorithm understanding for detecting and locating cycles. ✅ Learned how mathematical reasoning helps pinpoint the start node of a loop. ✅ Reinforced efficient use of pointer manipulation in linked list problems. #LeetCode #100DaysOfCode #Java #LinkedList #CycleDetection #FloydsAlgorithm #DSA #CodingJourney #WomenInTech #ProblemSolving
To view or add a comment, sign in
-
-
🔥 Day 113 of My DSA Challenge – Word Search 🔷 Problem : 79. Word Search 🔷 Goal : Check if a given word exists in a 2D grid by connecting sequentially adjacent letters (horizontally or vertically). Same cell cannot be used more than once. 🔷 Key Insight : This is a DFS + backtracking problem. Start from every cell matching the first character. Explore all 4 directions recursively. Track visited cells to avoid reusing letters. Backtrack when a path fails. This teaches how to explore grids efficiently using recursion and state tracking. 🔷 Approach : 1️⃣ Iterate over all cells to find starting points 2️⃣ DFS recursively for adjacent letters 3️⃣ Use a visited matrix to avoid reusing cells 4️⃣ Backtrack if the path does not lead to the word Time Complexity: O(m × n × 4^k) where k = length of word Space Complexity: O(m × n) for visited + recursion stack Word Search reinforces grid DFS + backtracking patterns. Explore all possibilities, track state carefully, backtrack on failure. This pattern is useful for : ✅ Maze solving ✅ Island counting problems ✅ Pathfinding & puzzle problems Every day, a new pattern becomes familiar. Step by step, the mind gets sharper. 🚀 #Day113 #DSA #100DaysOfCode #DFS #Backtracking #LeetCode #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #DeveloperJourney
To view or add a comment, sign in
-
-
🔥 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
To view or add a comment, sign in
-
-
✅Day 46 : Leetcode 69 - Sqrt(x) #60DayOfLeetcodeChallenge 🧩 Problem Statement Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer y should satisfy the condition: y * y <= x < (y + 1) * (y + 1) You must not use any built-in exponent functions such as pow(x, 0.5) or Math.sqrt(x). 💡 My Approach I used a binary search approach to efficiently find the integer square root. The search space is between 1 and x. At each step, I calculate mid and compute val = (long) mid * mid to avoid overflow. If val <= x, I move to the right half (low = mid + 1) and update the answer as mid. If val > x, I move to the left half (high = mid - 1). When the loop ends, ans contains the largest integer whose square is less than or equal to x. ⏱ Time Complexity O(log x) — Binary Search reduces the range by half each time. 💾 Space Complexity O(1) — Constant extra space. #LeetCode69 #BinarySearch #Math #SquareRoot #IntegerSquareRoot #Java #DataStructures #Algorithms #DSA #LeetCodeEasy #ProblemSolving #EfficientCode #OverflowHandling
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