🚀 112 days of #200DaysOfCode Problem: 454. 4Sum II Problem Statement: Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0. Approach: Used a HashMap to store sums of pairs from the first two arrays and their frequencies. Then iterated over all pairs from the next two arrays, checking if the complement exists in the map to count valid tuples efficiently. Logic: Harnessed hash mapping to reduce a brute-force O(n⁴) approach to O(n²), making the solution highly efficient for large inputs. 👉 Question link 🔗: https://lnkd.in/gsm79HER #LeetCode #Java #HashTable #Array #FourSum #HashMap #DSA #Coding #Algorithms #InterviewPrep #200DaysOfCode
Solved 4Sum II problem using HashMap in 112 days of #200DaysOfCode
More Relevant Posts
-
🚀 116 days of #200DaysOfCode Problem: 113. Path Sum II Problem Statement: Given the root of a binary tree and an integer targetSum, return all root-to-leaf paths where the sum of the node values in the path equals targetSum. Each path should be returned as a list of the node values. Approach: Used Depth-First Search (DFS) to explore all root-to-leaf paths while tracking the current path and sum. Added valid paths to the result when a leaf was reached and the sum matched the target. Logic: DFS with backtracking efficiently explores all possible paths and ensures only valid ones are stored. This approach is intuitive for tree problems and leverages recursion for clean path management. 👉 Question link 🔗: https://lnkd.in/gEp7MAYW #LeetCode #Java #Tree #DFS #Backtracking #DSA #Coding #Algorithms #InterviewPrep #200DaysOfCode
To view or add a comment, sign in
-
-
#Day14 94 – Binary Tree Inorder Traversal 💡 Approach: Used recursive depth-first search to traverse left subtree, process current node, then traverse right subtree. This follows the natural inorder sequence where nodes are visited in ascending order for BSTs. #LeetCode #Java #BinaryTree #DataStructures #Algorithms #Recursion #DFS #ProblemSolving #Coding #Tech #SoftwareEngineering #DailyCoding
To view or add a comment, sign in
-
-
🌿 Day 74 of #100DaysOfCode 🌿 💡 Problem: Binary Tree Preorder Traversal – LeetCode 🚀 Approach: Used a recursive traversal to explore nodes in the order Root → Left → Right. Preorder traversal is all about visiting the leader first — just like taking the initiative before exploring possibilities! 💫 📊 Complexity Analysis: Time Complexity: O(n)** — every node is visited once Space Complexity: O(n)** — due to recursion stack ✅ Runtime: 0 ms (⚡ Beats 100%) ✅ Memory: 43.06 MB 🔑 Key Insight: Recursion helps untangle even the deepest branches — one root call at a time 🌱 #LeetCode #100DaysOfCode #BinaryTree #Recursion #CodingJourney #DSA #ProblemSolving #Java #Algorithms #ProgrammerLife #WomenInTech #CodeEveryday
To view or add a comment, sign in
-
-
#Day33 of Problem Solving Successfully solved the “Count Primes” problem 🧮 using the Sieve of Eratosthenes algorithm. ✅ Result: All test cases passed (66/66) ⚡ Runtime: 97 ms — Beats 57.06% of Java submissions 💾 Memory: 49.56 MB This problem deepened my understanding of prime number optimization and time complexity reduction through effective use of boolean arrays and loop boundaries. Every small optimization matters — it’s amazing how algorithmic thinking can turn a simple mathematical problem into a performance challenge. 💡 #LeetCode #Java #Coding #ProblemSolving #SieveOfEratosthenes #Algorithms #DataStructures #CodingJourney #SoftwareEngineering #DSA #LinkedIn #HackerRank
To view or add a comment, sign in
-
-
🌟 #PostLog23🌟 Problem: 1539. Kth Missing Positive Number This one was about finding the k-th missing positive integer from a sorted array — and I managed to solve it efficiently using binary search, achieving a 0 ms runtime (100% faster submissions) 🚀 💡 Key idea: Instead of checking each missing number one by one, binary search helps to quickly find the point where the count of missing numbers reaches k. This brings the time complexity down to O(log n) — much faster than a linear scan. ✅ Concepts reinforced: Binary search optimization Handling edge cases in sorted arrays Mathematical reasoning in array indexing #LeetCode #CodingChallenge #Java #BinarySearch #ProblemSolving #LearningJourney #DSA
To view or add a comment, sign in
-
-
Day 54 of My DSA Challenge Problem: Count the number of pairs in an array whose sum equals a given target. Approach: Instead of the brute-force O(N²) method that checks every pair, I optimized the solution using a HashMap for frequency counting. Traverse the array once. For each element, check if (target - current element) exists in the map. If it does, it means those previous elements can form valid pairs with the current one. Update the frequency of the current element in the map. This smart use of a HashMap allows counting pairs in a single pass. Complexity: Time: O(N) Space: O(N) Key Insight: Using a frequency map turns an otherwise nested loop problem into a single-pass efficient solution — a common and elegant trick in array-based problems. #Day54 #DSAChallenge #HashMap #Optimization #ProblemSolving #Java #CodingChallenge #Algorithms #DataStructures #100DaysOfCode #GeeksforGeeks #LeetCode #CodingJourney #ProgrammersLife #TechLearning
To view or add a comment, sign in
-
-
🚀 Topological Sort | DFS Approach | Java Today I learned about Topological Sorting using Depth First Search (DFS) — a fundamental algorithm for Directed Acyclic Graphs (DAGs). 🔹 Concept: Topological sorting gives a linear ordering of vertices such that for every directed edge u → v, vertex u comes before v in the ordering. 🔹 Real-world uses: Course scheduling (prerequisites) Task dependency resolution Build order in compilers ⏱ Time Complexity: O(V + E) — each vertex and edge is processed once during DFS. 💾 Space Complexity: O(V) — for recursion stack, visited array, and stack to store results. 🏷️ Hashtags: #TopologicalSort #DFS #GraphAlgorithms #Java #DataStructures #Algorithms #CodingJourney #ProblemSolving #ComputerScience #LearningDSA
To view or add a comment, sign in
-
Day 51 of My DSA Challenge Problem: Count all triplets (i, j, k) in an array such that arr[i] + arr[j] + arr[k] = target Example: Input → arr = [1, 2, 3, 4, 5], target = 9 Output → 2 (Triplets: [1,3,5] and [2,3,4]) My Approach: Instead of using a brute force O(N³) approach, I optimized it using HashMap + Two Loops. Logic Breakdown: Store frequency of all elements (from index 2 onwards) in a HashMap. Fix j, iterate i < j, and calculate target - (arr[i] + arr[j]). If that value exists in the HashMap → it forms valid triplets! After processing each j, reduce the count of future elements to maintain correctness. Time Complexity: O(N²) Space Complexity: O(N) #Day51 #DSAChallenge #HashMap #ProblemSolving #TripletsSum #DSA #CodingChallenge #Java #100DaysOfCode #CodeEveryday #GeeksforGeeks #LeetCode #DataStructures #Algorithms #TwoPointers #DSAwithJava #CodingCommunity #ProgrammingJourney #DeveloperMindset #TechLearning
To view or add a comment, sign in
-
-
#98day of #100DaysOfCode 🌿 LeetCode 1302: Deepest Leaves Sum Today’s problem was about exploring the depths of a binary tree 🌳 We needed to find the sum of all the deepest leaf nodes — those that rest at the very bottom of the tree. 🧠 Approach: Two main ways to solve it: 1️⃣ Level Order Traversal (BFS): Traverse level by level; the last level’s sum is the answer. 2️⃣ Depth-first Search (DFS): Track maximum depth and accumulate the sum of deepest nodes. 📈 Complexity: Time: O(n) Space: O(n) 💬 Learning: Whether in trees or life, depth reveals value — the deeper you go, the richer the sum 🌱 #LeetCode #DSA #BinaryTree #CodingChallenge #java #ProblemSolving #LeetCodeDaily #100DaysOfCode #Algorithm
To view or add a comment, sign in
-
-
#Day_31 Today’s challenge was an interesting matrix binary search problem — “Find a Peak Element II”-> it's a medium level question. The task: Given a 2D grid, find any element that’s strictly greater than its top, bottom, left, and right neighbors. A brute-force solution would check every element’s neighbors — but that’s O(m × n). Instead, I used a binary search on columns to cut the search space efficiently. Here’s the idea: Pick the middle column. Find the maximum element in that column. Compare it with its left and right neighbors. If it’s greater than both — you’ve found a peak. Otherwise, move to the side that has a larger neighbor (since a peak must exist there). This clever approach brings the complexity down to O(m × log n) — a huge win on large matrices. This problem was a great reminder that binary search isn’t just for 1D arrays — it can be applied creatively in multiple dimensions too #Coding #LeetCode #Java #BinarySearch #ProblemSolving #LearningEveryday
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