🚀 Day 54 – 100 Days Coding Challenge 📌 Problem: Three Sum ⚙️ Approach • First, sort the array to make it easier to apply the two-pointer technique • Iterate through the array and fix one element at a time • For each fixed element, use two pointers (left and right) to find pairs whose sum equals the negative of the fixed element • Skip duplicate elements to avoid repeating triplets • Move pointers based on the sum: – If sum == 0 → store the triplet and move both pointers – If sum < 0 → move left pointer forward – If sum > 0 → move right pointer backward 🧠 Logic Used • Sorting + Two Pointer Technique • Handling duplicates efficiently to ensure unique triplets • Reducing time complexity from brute force O(n³) to O(n²) 🔗 GitHub: https://lnkd.in/g_3x55n8 ✅ Day 54 Completed #100DaysOfCode #Java #DSA #ProblemSolving #Algorithms #DataStructures #LeetCode #CodingPractice #TwoPointers #ArrayProblems
Three Sum Problem Solution with Two Pointer Technique
More Relevant Posts
-
Day 60 of My 90-Day Coding Challenge Today I worked on a classic recursion + backtracking problem — and it really tested how well I understand breaking problems into smaller decisions. At first, it feels messy: multiple partitions, multiple choices, and many possible paths. But once you start thinking in terms of: -“Try every possible cut and validate it” the structure becomes clear. Key learning: • Recursion is about exploring all paths, not rushing to the answer • Validity checks (like palindrome here) are what control the tree • Clean backtracking (add → recurse → remove) is everything One thing that really helped today: Even if you don’t know where to start, just begin drawing the recursion tree. As you expand it step by step, the logic starts revealing itself — what choices to make, when to stop, and how to backtrack. What stood out today: Clarity in recursion doesn’t come from memorizing patterns — it comes from visualizing the process. Still improving. #90DaysOfCode #DSA #Java #Recursion #Backtracking #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 8 of 30 Days Coding Challenge Today I solved a problem on LeetCode: Minimum Distance Between Three Equal Elements. 🔍 Approach: Initially implemented a brute-force solution using three nested loops (O(n³)). It worked for smaller constraints but highlighted the importance of optimizing. 💡 Key Learning: Instead of checking all possible triplets, grouping indices of identical elements and analyzing consecutive occurrences leads to a much more efficient solution. ⚡ Optimization Insight: Reduced time complexity from O(n³) → O(n) Leveraged HashMap to store indices and process only relevant combinations. 📈 Takeaway: This problem reinforced an important concept: 👉 When dealing with repeated elements, think in terms of grouping and patterns rather than brute force. Consistency is key — learning something new every day and improving step by step. #Day8 #30DaysOfCode #CodingChallenge #LeetCode #Java #DataStructures #Algorithms #ProblemSolving #CodingJourney #SoftwareDevelopment #LearnToCode #TechGrowth
To view or add a comment, sign in
-
-
🚀 Day 13 / 50 – Wild Coding Kickoff 🔥 Today’s problem looked like it wanted a complicated solution… but it ended up teaching me something much simpler. I read the question and instantly thought: “Okay, substring search… this might get tricky.” 👀 Loops, comparisons, edge cases… my mind started going there. But then I stopped and asked: 👉 “Is there a simpler way?” That’s when I used this: class Solution { public int strStr(String haystack, String needle) { int index = haystack.indexOf(needle); return index; } } 💡 What does indexOf() actually do? It searches for the first occurrence of needle inside haystack Returns: ✅ The starting index if found ❌ -1 if the substring is not present 🔥 Example haystack = "sadbutsad" needle = "sad" 👉 Output: 0 (because "sad" starts at index 0) 🧠 What I learned today Sometimes we try to prove we know everything… But real skill is knowing when to keep things simple. Using built-in methods effectively is also a skill. #Day13 #50DaysOfCode #WildCodingKickoff #LeetCode #Java #CodingJourney #Consistency #KeepItSimple #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Solved LeetCode Problem #58 – Length of Last Word Today I worked on a simple yet insightful string manipulation problem that emphasizes attention to edge cases. 🔍 Problem Insight: Given a string containing words and spaces, the goal is to find the length of the last word, ignoring any trailing spaces. 💡 Approach Used: Instead of using built-in methods like split(), I implemented an optimized approach by: Traversing the string from the end Skipping trailing spaces Counting characters until the next space is encountered This approach avoids extra space usage and improves efficiency. 🧠 Key Learning: Importance of handling edge cases like trailing spaces How reverse traversal can simplify string problems Writing memory-efficient solutions 📈 Complexity: Time: O(n) Space: O(1) ✨ Problems like this help strengthen: String manipulation skills Logical thinking Writing clean and optimized code Consistency is key—one step closer to mastering DSA! 💪 #LeetCode #DSA #StringManipulation #Coding #ProblemSolving #Java #TechJourney
To view or add a comment, sign in
-
-
Day 8/30 of my #30DaysDSAChallenge 🚀 Solved Problem 70 on LeetCode: Climbing Stairs 🧗♂️ At first glance, it looks simple — but the real learning was in identifying the pattern. This problem is a classic example of how Dynamic Programming works behind the scenes. 💡 Key Insight: To reach step n, you can either come from n-1 or n-2. Which leads to a Fibonacci-like relation: 👉 ways(n) = ways(n-1) + ways(n-2) Instead of using recursion (which is inefficient), I implemented an optimized iterative approach with O(n) time and O(1) space. 📚 What I learned today: Recognizing DP patterns in problems Converting recursion → optimized iteration Importance of space optimization Small steps every day, but getting stronger with problem-solving 💪 #DSA #LeetCode #Java #ProblemSolving #CodingJourney #Consistency #100DaysOfCode
To view or add a comment, sign in
-
-
Day 14 of #50DaysOfLeetCode Challenge Today’s coding challenge was Rotate List (LeetCode 61). The goal is to rotate a linked list to the right by k places. At first, it sounds like you need to move nodes one by one, but that’s inefficient. The key to a high-performance solution is to treat the list like a loop! The Efficiency Strategy: 1. Calculate Length: First, find the total length of the list (n). 2. Handle Large K: If k is larger than n, we only need to rotate k % n times. This avoids unnecessary cycles. 3. Make it a Circle: Connect the last node's "next" pointer to the original head to create a temporary circular list. 4. Find the New Break: Move (n - (k % n)) steps from the head to find the new tail of the rotated list. 5.Break the Loop: Save the node after the new tail as the new head, and then set the new tail's "next" to null. #LeetCode #BitManipulation #Java #Coding #Efficiency #TechLearning
To view or add a comment, sign in
-
-
🚀 Day 15 of 180 — 3Sum Closest ✅ LeetCode 16 — 3Sum Closest First sort the array. Then fix one element and use two pointers for the remaining two — one at left, one at right. For every triplet I calculate the sum and check how far it is from the target: distance = |target - sum| If this distance is less than my current minimum difference, I update my answer. Moving pointers is simple — if sum is greater than target → move right pointer left if sum is less than target → move left pointer right if sum equals target → that's the closest it can get, return immediately The key thing I made sure — keep tracking the minimum difference throughout and update result whenever a closer sum is found. Day 15 done. 165 to go. 🔥 #180DaysDSA #Day15 #LeetCode #Java #DSA #TwoPointers #Sorting #ThreeSum #DSAJourney #CodingJourney #Programming #DataStructures #Algorithms #ProblemSolving #BuildInPublic #CodeNewbie #LearnToCode #100DaysOfCode #SoftwareDevelopment #Developer #StudentDeveloper #TechCommunity #LinkedInTech #CompetitiveProgramming
To view or add a comment, sign in
-
-
🚀 Day 2 of My Coding Challenge Improving my problem-solving skills step by step! Today I solved an important array problem from LeetCode. 🔹 Platforms: LeetCode & GeeksforGeeks 🔹 Problem: LeetCode #189 – Rotate Array 🔹 Problem Statement: Rotate the array to the right by k steps. 🔹 Approach: I used the Reversal Algorithm for an optimized solution: 1️⃣ Reverse the entire array 2️⃣ Reverse first k elements 3️⃣ Reverse remaining elements 🔹 Example: Input: [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4] 🔹 What I learned: ✔ Optimized approach from brute force to O(n) ✔ Importance of array manipulation techniques ✔ Handling edge cases like k > n 💻 Code: import java.util.Arrays; public class RotateArrayLeetCode189 { ``` public static void reverse(int[] arr, int start, int end) { while (start < end) { int temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } } public static void rotate(int[] arr, int k) { int n = arr.length; k = k % n; if (k < 0) { k = k + n; } // Step 1: Reverse entire array reverse(arr, 0, n - 1); // Step 2: Reverse first k elements reverse(arr, 0, k - 1); // Step 3: Reverse remaining elements reverse(arr, k, n - 1); } public static void main(String[] args) { int[] arr = {1, 2, 3, 4, 5, 6, 7}; int k = 3; rotate(arr, k); System.out.println(Arrays.toString(arr)); } ``` } 🔗 GitHub: https://lnkd.in/g-wNSrPq #Java #DSA #LeetCode #CodingChallenge #50DaysOfCode #LearningJourney #PlacementPreparation
To view or add a comment, sign in
-
Day 55 of 100 Days of LeetCode 💻 Today I solved Longest Consecutive Sequence — and honestly, this one taught me more about coding discipline than algorithms. At first, my approach was correct: Used HashSet for O(1) lookup Applied the “start of sequence” logic But I still got TLE. The reason? A tiny mistake: if(!set.contains(num-1)); That single ; made my condition useless and turned my O(n) solution into O(n²). 💡 Lesson learned: Don’t just think your logic is right → verify what your code actually does Small syntax mistakes can completely break optimal solutions Debugging is just as important as problem-solving Finally fixed it and got Accepted ✅ Slowly improving not just in DSA, but in writing cleaner and more careful code. #100DaysOfLeetCode #DSA #Java #CodingJourney #Learning
To view or add a comment, sign in
-
-
At first, the Rotate Image problem looked tricky. Rotating a matrix in-place isn’t something that feels obvious right away. But after thinking about it, I realized it’s not about rotation directly, it’s about transforming the matrix step by step. By first flipping it across the diagonal (transpose) and then reversing each row, the rotation happens naturally. Moments like this remind me that in coding, the right approach often matters more than the problem itself. Learning to break problems down is the real skill. RAVI KUMAR Coding Blocks Sunstone #Coding #DSA #Java #ProblemSolving #GrowthMindset #Learning
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