Leetcode Practice - 18. 4Sum Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: ✅ 0 <= a, b, c, d < n ✅ a, b, c, and d are distinct. ✅ nums[a] + nums[b] + nums[c] + nums[d] == target You may return the answer in any order. Example 1: Input: nums = [1,0,-1,0,-2,2], target = 0 Output: [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]] Example 2: Input: nums = [2,2,2,2,2], target = 8 Output: [[2,2,2,2]] Constraints: 1 <= nums.length <= 200 -109 <= nums[i] <= 109 -109 <= target <= 109 #LeetCode #Java #CodingPractice #ProblemSolving #DSA #Array #DeveloperJourney #TechLearning
4Sum LeetCode Solution in Java
More Relevant Posts
-
🚀 Just crossed 130 LeetCode problems solved! Here are the 5 patterns that unlocked the majority of them: 1️⃣ Sliding Window — O(n) solutions hiding inside O(n²) problems 2️⃣ Two Pointers — eliminate the inner loop, think from both ends 3️⃣ BFS/DFS — once you see graphs everywhere, you can't unsee them 4️⃣ Dynamic Programming — break it into subproblems, trust the recurrence 5️⃣ Binary Search — not just for sorted arrays; think about "search space" Most medium problems are just combinations of these 5. The real milestone isn't the number — it's the moment you stop Googling the approach and start reasoning from first principles. Onto the next 130. 💻 #LeetCode #DataStructures #Algorithms #Java #DSA #Tech
To view or add a comment, sign in
-
-
🚀 Day 89 / 100 – LeetCode Challenge Today’s problem: Symmetric Tree (Easy) 🌳 👉 Problem: Check whether a binary tree is a mirror of itself (symmetric around its center). 💡 Key Insight: A tree is symmetric if the left and right subtrees are mirror images. That means: Left.left == Right.right Left.right == Right.left 🧠 Approach (Recursive): If both nodes are null → symmetric ✅ If only one is null → not symmetric ❌ If values match → recursively check cross children ⏱ Complexity: Time: O(n) Space: O(h) 🔥 Takeaway: This problem teaches how to think in terms of mirror recursion instead of normal traversal. #Day89 #LeetCode #100DaysOfCode #Java #DSA #CodingChallenge #BinaryTree #Recursion
To view or add a comment, sign in
-
-
Crossed 90+ DSA problems on LeetCode — but focusing on something more important than just numbers. • Solving problems with complete understanding (no shortcuts) • Practicing patterns like Binary Search, Hashing, Sliding Window • Re-solving to improve recall under pressure • Applying this in real OAs and contests Recently attempted OAs involving Graphs and Dynamic Programming — a strong reminder that real performance matters more than problem count. Alongside DSA, I’m building backend systems using Java & Spring Boot to stay aligned with real-world development. Consistently working on improving problem-solving speed, clarity, and correctness. #DSA #Java #BackendDevelopment #LeetCode #SoftwareEngineering
To view or add a comment, sign in
-
-
📘 DSA Journey — Day 33 Today’s focus: Binary Search for next greater element. Problem solved: • Find Smallest Letter Greater Than Target (LeetCode 744) Concepts used: • Binary Search • Upper bound concept • Circular handling Key takeaway: The goal is to find the smallest character strictly greater than a given target in a sorted array. This is a classic upper bound problem: We use binary search to find the first element greater than the target. During search: • If letters[mid] > target, store it as a possible answer and move left • Else move right An important edge case: If no character is greater than the target, we return the first element (circular behavior). Continuing to strengthen binary search patterns and problem-solving consistency. #DSA #Java #LeetCode #CodingJourney
To view or add a comment, sign in
-
-
🚀 LeetCode Challenge 4/50 💡 Approach: Reverse Traversal (No Split!) The easy way out? s.trim().split(" ") — but that creates an extra array and costs O(n) space. Instead, I traversed from the end of the string directly! 🔍 Key Insight: → Start from the last character → Skip any trailing spaces first → Count characters until the next space — that's your answer! 📈 Complexity: ✅ Time: O(n) — at most one full scan ✅ Space: O(1) — zero extra memory used The best solution isn't always the most obvious one. Sometimes looking from a different angle (literally, from the end!) makes all the difference. 🔄 #LeetCode #DSA #StringManipulation #Java #ADA #PBL2 #LeetCodeChallenge #Day4of50 #CodingJourney #ComputerEngineering #AlgorithmDesign #LengthOfLastWord
To view or add a comment, sign in
-
-
💡Day 44 of LeetCode Problem Solved! 🔧 🌟205. Isomorphic Strings🌟 Task : • Given two strings s and t, determine if they are isomorphic. • Two strings s and t are isomorphic if the characters in s can be replaced to get t. • All occurrences of a character must be replaced with another character while preserving the order of characters. • No two characters may map to the same character, but a character may map to itself. Example 1: Input: s = "egg", t = "add" Output: true Explanation: The strings s and t can be made identical by: Mapping 'e' to 'a'. Mapping 'g' to 'd'. Example 2: Input: s = "f11", t = "b23" Output: false Explanation: The strings s and t can not be made identical as '1' needs to be mapped to both '2' and '3'. #LeetCode #Java #DSA #ProblemSolving #Consistency #100DaysOfChallenge #CodingJourney #KeepGrowing
To view or add a comment, sign in
-
-
💻 Interesting Java problem: Find the closest target in a circular array Given a words[] array, a target, and a startIndex, the task is to find the shortest circular distance to the target. Leetcode Problem :https://lnkd.in/g3RbdChE Core idea: For every matching target: find direct distance → Math.abs(i - startIndex) find circular distance → n - dist take the minimum. This is a neat example of how circular arrays require us to think beyond normal linear traversal. Small twist, smart logic. 🚀 #Java #Algorithms #DSA #CodingInterview #ProblemSolving #LeetCode
To view or add a comment, sign in
-
-
Solving LeetCode Problem | Day 6 • Problem: Reverse Linked List | LeetCode 206 • Approach: Used an iterative approach with three pointers: prev, curr, and next. Started from the head and reversed the direction of each node one by one by updating links: Stored next node Reversed current node’s pointer Moved all pointers forward This continues until the list is fully reversed, and prev becomes the new head. Key Insight: The tricky part is not losing the next node while reversing links. If you mess that up, the list is gone. • Time Complexity: O(n) • Space Complexity: O(1) #leetcode #dsa #algorithms #datastructures #coding #programming #java #linkedlist #problemsolving #tech #softwareengineering #developer #100daysofcode
To view or add a comment, sign in
-
-
Day 93 - LeetCode Journey Solved LeetCode 9: Palindrome Number in Java ✅ At first glance, it feels like a string problem… but the real challenge is solving it without converting to string. Instead of reversing the whole number, I reversed only half of it and compared both parts. This avoids overflow and keeps it efficient. Smart approach > brute force 💡 Key takeaways: • Handling edge cases (negative numbers, trailing zeroes) • Reversing only half of the number • Avoiding extra space (no string conversion) • Writing optimized mathematical logic ✅ All test cases passed ⚡ O(log n) time and O(1) space Sometimes the best solutions are the simplest ones, just a different way of thinking 🔥 #LeetCode #DSA #Java #Math #ProblemSolving #CodingJourney #InterviewPrep #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 27/100 – LeetCode DSA Challenge 📌 Problem Solved: Find All Numbers Disappeared in an Array Today’s problem focused on identifying missing numbers from an array where elements are in the range [1, n]. 🔍 Approach I Used (Easy Method): Created a boolean array to track visited numbers Marked each number as present Iterated from 1 to n to find missing elements 💡 Key Concepts Learned: How to use index-based mapping for arrays Importance of range constraints [1, n] Difference between brute force vs optimized approach Using extra space to simplify logic 🧠 What I Understood Today: If a problem says numbers are in range [1, n], we can directly map values to indices Tracking frequency or presence is a powerful technique Writing clean and simple logic first is more important than jumping to optimization 🔥 Next Step: I will try the optimized approach (O(1) space) using index marking (negative marking technique) 📈 Improving step by step in DSA — consistency is the key! #Day27 #LeetCode #DSA #100DaysOfCode #CodingJourney #PlacementsPreparation #Java
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