Day 19/100 of DSA , (Arrays) 🚀Toady I Solved: classic 4Sum problem I worked on solving the 4Sum problem using Java, where the goal is to find all unique quadruplets in an array whose sum equals a given target value. 🔹 Approach Used: • First, sort the array to make traversal easier and handle duplicates. • Fix the first two elements using nested loops. • Use the two-pointer technique to find the remaining two elements whose sum matches the target. • Carefully skip duplicate values to ensure only unique quadruplets are included in the result. ⚡ Time Complexity: O(n³) ⚡ Space Complexity: O(1) (excluding the output list) Problems like this are a great way to strengthen understanding of two-pointer patterns and array manipulation. Consistently practicing these patterns helps improve logical thinking, debugging skills, and writing optimized code. Every problem solved is another step toward becoming a better developer. 🚀 #Java #DSA #Algorithms #ProblemSolving #CodingJourney #LearningInPublic #JavaDeveloper
Java 4Sum Problem Solution
More Relevant Posts
-
Diving into Linked Lists: Part 1 of my Java DSA Series Taking the next step in my algorithms journey by moving from arrays to dynamic memory allocation. Working with Linked Lists requires a completely different mental model, heavily relying on node references and pointer manipulation. To make sure I fully grasp the mechanics, I am splitting this topic into two parts. Here is what I implemented from scratch in Part 1: -Core Operations: Building the Node class and logic to Add, Remove, and Print elements at various positions. -Search Algorithms: Implementing both Iterative and Recursive search methods. -Reversal: Coding an in-place reversal algorithm using standard pointer manipulation. -Palindrome Checker: Utilizing the Slow and Fast pointer (Tortoise and Hare) approach to find the midpoint and verify palindromes. Getting comfortable with pointers has been a challenging but rewarding shift in problem-solving. Part 2 will be coming soon. #DSA #Java #LinkedList #Algorithms #ProblemSolving #SoftwareEngineering #OpenLearning
To view or add a comment, sign in
-
🚀 Day 86 of My DSA Journey | Subsets – Recursion ➡️ Bit Manipulation 💡 Yesterday, I solved the Subsets problem (LeetCode 78) using recursion (backtracking). Today, I challenged myself to solve the same problem using a different approach — Bit Manipulation 🔥 🔹 What changed? Instead of recursion, I used bit masking to generate all subsets. Every number from 0 to 2^n - 1 represents a subset in binary form. 👉 Core idea: (i & (1 << j)) != 0 This checks whether the j-th element should be included in the subset. 📌 Example: nums = [1,2,3] i = 5 → binary (101) Subset → [1,3] ⚡ Key Learning: One problem can have multiple approaches Recursion = intuitive Bit manipulation = optimized & clever Strengthened my understanding of binary concepts ⏱️ Time Complexity: O(n * 2^n) 📦 Space Complexity: O(2^n) Consistency is the key — learning, applying, and improving every single day 💯 #Day87 #DSA #Java #BitManipulation #Recursion #LeetCode #CodingJourney #PlacementPreparation
To view or add a comment, sign in
-
-
🚀 Day 58 / 100 – LeetCode Challenge ✅ Problem Solved: Binary Tree Postorder Traversal 📊 Difficulty: Easy 💻 Language: Java Today’s problem focused on understanding tree traversal, specifically Postorder Traversal (Left → Right → Root). 🔍 Key Learnings: Mastered recursive approach for tree traversal Understood how DFS (Depth First Search) works in binary trees Strengthened problem-solving with clean and efficient logic ⚡ Performance: Runtime: 0 ms (Beats 100%) 🔥 Memory: 42.96 MB 💡 Approach: Used a simple recursive helper function: Traverse left subtree Traverse right subtree Add root node value This problem may be easy, but it builds a strong foundation for advanced tree problems 💪 📈 Consistency is key — 58 days down, 42 more to go! #LeetCode #100DaysOfCode #Java #DataStructures #CodingJourney #BinaryTree #DSA #Learning #Consistency
To view or add a comment, sign in
-
-
🚀 DSA Learning Journey | Day 2 | Java Solved “Next Permutation.” 💡 Key Idea: Find the first decreasing element from the right, swap it with the next greater element, then reverse the remaining suffix to get the next lexicographical permutation. ⚙ Implementation • Language: Java • Time Complexity: O(n) • Space Complexity: O(1) 📚 Learning how permutation logic works and how reversing the suffix ensures the next smallest arrangement. #Java #DSA #LeetCode #ProblemSolving #JavaDeveloper #Algorithms
To view or add a comment, sign in
-
-
Day 57 of #100DaysOfLeetCode 💻✅ Solved #506. Relative Ranks problem in Java. Approach: • Iterated through each player's score • Compared it with all other scores to determine its rank • Increased rank whenever a higher score was found • Assigned medals for top 3 ranks: Gold, Silver, Bronze • Converted remaining ranks to string and stored in result array Performance: ✓ Runtime: 124 ms (Beats 5.06% submissions) ✓ Memory: 46.76 MB (Beats 99.84% submissions) Key Learning: ✓ Understood ranking logic using comparison ✓ Practiced nested loop approach for problem solving ✓ Learned the importance of optimizing time complexity Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #Sorting #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
Day 46 of #100DaysOfLeetCode 💻✅ Solved #374. Guess Number Higher or Lower problem in Java. Approach: • Used Binary Search to efficiently guess the number. • Calculated mid using low + (high - low) / 2 to avoid overflow. • Used the guess(mid) API to check if the number is higher, lower, or correct. • Updated the search range accordingly until the number was found. Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 41.68 MB (Beats 97.84% submissions) Key Learning: ✓ Practiced implementing binary search on a real problem ✓ Learned how to safely calculate mid to prevent integer overflow ✓ Strengthened problem-solving skills with search algorithms Learning one problem every single day 🚀 #Java #LeetCode #DSA #BinarySearch #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🚀 Day 99 of My 100 Days LeetCode Challenge | Java Today’s problem was all about randomization and linked list traversal — a nice break from heavy DP and matrices. The challenge was to design a system that returns a random node’s value from a singly linked list, ensuring that every node has an equal probability of being chosen. Since linked lists don’t allow direct indexing, the key idea was to first determine the size of the list, and then generate a random index to fetch the corresponding node. This approach ensures uniform randomness while keeping the implementation simple and efficient. ✅ Problem Solved: Linked List Random Node ✔️ All test cases passed (8/8) ⏱️ Runtime: 11 ms 🧠 Approach: Linked List Traversal + Randomization 🧩 Key Learnings: ● Randomization problems require ensuring uniform probability distribution. ● Linked lists limit direct access, so traversal becomes essential. ● Precomputing size can simplify random selection. ● Sometimes simple approaches are the most effective. ● Understanding data structure limitations helps design better solutions. This problem highlighted how probability + data structures can come together in elegant ways. 🔥 Day 99 complete — sharpening my understanding of randomization and linked list behavior. #LeetCode #100DaysOfCode #Java #LinkedList #Randomization #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 90 of My 100 Days LeetCode Challenge | Java Today’s challenge was a fascinating logic + mathematical insight problem. The task was to generate a binary string that does not exist in a given list of binary strings, where all strings have the same length. Instead of trying every possible combination, the solution becomes much simpler when you use the idea of diagonal flipping. By flipping the i-th bit of the i-th string, we guarantee that the newly created string differs from every string in the list at least in one position. This clever trick ensures the generated string is always unique. ✅ Problem Solved: Find Unique Binary String ✔️ All test cases passed (186/186) ⏱️ Runtime: 0 ms 🧠 Approach: Mathematical Insight (Diagonal Construction) 🧩 Key Learnings: ● Sometimes the smartest solutions come from mathematical reasoning rather than brute force. ● The diagonalization technique guarantees uniqueness. ● Understanding problem constraints can drastically simplify the approach. ● Logical insights can reduce exponential possibilities to linear solutions. ● Elegant algorithms often come from simple observations. This problem was a great reminder that a small logical trick can outperform complex algorithms. 🔥 Day 90 complete — sharpening my problem-solving intuition and algorithmic thinking. #LeetCode #100DaysOfCode #Java #Math #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🚀 Day 97 of My 100 Days LeetCode Challenge | Java Today’s problem was a solid exercise in matrix processing and prefix sum optimization. The goal was to count the number of submatrices whose sum is less than or equal to a given value (k). A brute-force approach would be too slow, so the key was to use 2D prefix sums to efficiently compute submatrix sums. By converting the matrix into a prefix sum matrix, we can calculate the sum of any submatrix in constant time, making the overall solution much more efficient. ✅ Problem Solved: Count Submatrices With Sum ≤ K ✔️ All test cases passed (859/859) ⏱️ Runtime: 7 ms 🧠 Approach: 2D Prefix Sum 🧩 Key Learnings: ● Prefix sums are powerful for optimizing repeated range sum queries. ● 2D prefix sums extend the same idea from arrays to matrices. ● Preprocessing can drastically reduce computation time. ● Avoiding brute force is key in large input problems. ● Matrix problems often become easier with the right transformation. This problem reinforced how preprocessing techniques like prefix sums can turn complex problems into efficient solutions. 🔥 Day 97 complete — sharpening matrix optimization and prefix sum skills. #LeetCode #100DaysOfCode #Java #PrefixSum #Matrix #Algorithms #ProblemSolving #DSA #CodingJourney #Consistency
To view or add a comment, sign in
-
-
Day 45 of #100DaysOfLeetCode 💻✅ Solved Simple #268. Missing Number problem in Java. Approach: • Calculated the expected sum of numbers from 0 to n using the formula n(n+1)/2 • Traversed the array and calculated the actual sum of the elements • Subtracted the actual sum from the expected sum • The difference gives the missing number in the array Performance: ✓ Runtime: 0 ms (Beats 100% submissions) 🚀 ✓ Memory: 47.60 MB (Beats 29.84% submissions) Key Learning: ✓ Practiced using mathematical formulas to simplify problems ✓ Learned how sum comparison can help find a missing element efficiently ✓ Strengthened problem-solving skills with arrays Learning one problem every single day 🚀 #Java #LeetCode #DSA #Arrays #ProblemSolving #CodingJourney #100DaysOfCode
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