Day 33 of #50DaysOfLeetCodeChallenge Problem: 3Sum Given an integer array, find all unique triplets that sum up to zero. 🔍 Approach: Used the Two Pointer Technique after sorting the array. For each element, I fixed one number and used two pointers (left and right) to find pairs that complement it to make zero — skipping duplicates along the way for efficiency. 🧠 Key Takeaways: Sorting simplifies duplicate handling. Two pointers help reduce time complexity from O(n³) → O(n²). Clean implementation using conditions to skip repeated numbers. ⏱️ Runtime: 31 ms (beats 56.43%) 💾 Memory: 51.76 MB #LeetCode #CodingChallenge #ProblemSolving #Java #DSA #TwoPointers #50DaysOfCode
Solved 3Sum with Two Pointers Technique in Java
More Relevant Posts
-
📌 Day 2/100 – Remove Element (LeetCode 27) 🔹 Problem: Given an integer array nums and a value val, remove all instances of that value in-place and return the new length of the array. The order of elements can be changed. 🔹 Approach: Used the two-pointer technique to efficiently modify the array in-place. One pointer iterates through the array, while the other tracks the position to overwrite non-val elements. Returned the position of the second pointer as the new length. 🔹 Key Learning: Strengthened understanding of in-place array manipulation. Improved logic building for pointer movement and conditional overwriting. Learned how to minimize extra space usage while maintaining readability and clarity. Another small yet powerful step toward mastering array-based problems! 💻 🔥 #100DaysOfCode #LeetCode #Java #ProblemSolving #TwoPointers #DSA #CodingJourney
To view or add a comment, sign in
-
-
📌 Day 3/100 - Remove Duplicates from Sorted Array (LeetCode 26) 🔹 Problem: Given a sorted array, remove the duplicates in-place so that each element appears only once and return the new length. You must modify the array without using extra space for another array. 🔹 Approach: I used a simple counting-based approach: Iterate through the array using a single loop. If the current element is the same as the next, skip it. Otherwise, place it at the current count index and increment count. Finally, return count as the number of unique elements. 🔹 Key Learning: Practiced in-place array modification efficiently without extra space. Improved understanding of loop-based filtering logic. Realized that sometimes the simplest linear approach works best! Consistency compounds — each problem adds a new layer of confidence! 🚀#100DaysOfCode #LeetCode #Java #ProblemSolving #Array #DSA #TwoPointers
To view or add a comment, sign in
-
-
✅ Day 32 of #100DaysOfCode Challenge 📘 LeetCode Problem 108: Convert Sorted Array to Binary Search Tree 🧩 Problem Statement: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). A height-balanced BST ensures both left and right subtrees of every node differ in height by at most 1. 💡 Simple Idea: Pick the middle element as the root. Elements on the left become the left subtree. Elements on the right become the right subtree. Repeat the same steps recursively. ⚙ Complexity: ⏱ Time: O(n) 💾 Space: O(log n) (recursion stack height) 🌱 Step by step, building balance in both code and logic! #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinarySearchTree #Recursion #CodingChallenge
To view or add a comment, sign in
-
-
✅ Day 32 of #100DaysOfCode Challenge 📘 LeetCode Problem 108: Convert Sorted Array to Binary Search Tree 🧩 Problem Statement: Given a sorted array, convert it into a height-balanced Binary Search Tree (BST). A height-balanced BST ensures both left and right subtrees of every node differ in height by at most 1. 💡 Simple Idea: Pick the middle element as the root. Elements on the left become the left subtree. Elements on the right become the right subtree. Repeat the same steps recursively. ⚙ Complexity: ⏱ Time: O(n) 💾 Space: O(log n) (recursion stack height) 🌱 Step by step, building balance in both code and logic! #Day32 #100DaysOfCode #LeetCode #Java #DSA #BinarySearchTree #Recursion #CodingChallenge
To view or add a comment, sign in
-
-
Day 50 of #75DaysDSAChallenge Problem: 7. Reverse Integer Difficulty: 🟠 Medium Platform: LeetCode 🧩 Problem Statement Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes it to go outside the signed 32-bit integer range [-2³¹, 2³¹ - 1], return 0. Example: Input: x = 123 Output: 321 💡 Approach 1️⃣ Extract the last digit using x % 10. 2️⃣ Remove the last digit using x / 10. 3️⃣ Add the digit to the reversed number. 4️⃣ Before updating, check for overflow conditions. 5️⃣ Continue until all digits are processed. #LeetCode #Java #DSA #CodingChallenge #75DaysDSAChallenge #ProblemSolving #TechLearning #CodingJourney
To view or add a comment, sign in
-
-
#100DaysOfCode – Day 68 String Manipulation Problem 1:- Largest Odd Number in String Task:- Given a numeric string, return the largest-valued odd number (as a substring) or an empty string if none exists. Example: Input: num = "35427" → Output: "35427" My Approach: Started scanning the string from right to left. The first odd digit encountered marks the end of the required substring. Returned the substring from start to that index. Time Complexity:- O(N) Space Complexity:- O(1) Sometimes, it’s not about complex algorithms just a small logical observation can lead to an efficient solution. #takeUforward #100DaysOfCode #Java #ProblemSolving #LeetCode #CodeNewbie #StringManipulation #LogicBuilding #CleanCode
To view or add a comment, sign in
-
-
💻 #PostLog15 Problem: Find First and Last Position of Element in a Sorted Array (LeetCode #34) 🧩 Problem Summary: Given a sorted array and a target value, we need to find the starting and ending index of the target element. If the target is not present, return [-1, -1]. The challenge: solve it in O(log n) time complexity. ⚙️ Key Idea: I implemented two modified binary searches — One to find the first occurrence, and Another to find the last occurrence of the target. This approach leverages the efficiency of binary search to stay within logarithmic complexity. ✅ Takeaways: Binary search can be customized beyond simple value lookups. Clear separation of concerns (finding first vs. last) makes debugging easier. Edge cases (like empty arrays or missing targets) are essential to handle carefully. 🔢 Example: Input: nums = [5,7,7,8,8,10], target = 8 Output: [3, 4] #LeetCode #Java #ProblemSolving #BinarySearch #CodingJourney #DSA
To view or add a comment, sign in
-
-
#Day-39) Today #LeetCode3350: Adjacent Increasing Subarrays Detection II—a neat medium-level challenge that tests your ability to track increasing sequences and optimize comparisons. 🔍 Problem Brief: Given an array, find the maximum value of k such that two adjacent subarrays of length k are both strictly increasing. 💡 Approach: I used two passes to compute the longest increasing sequences from the left and right, then compared adjacent segments to find the optimal k. Efficient use of space with two arrays and a single traversal logic. #LeetCode #Java #ProblemSolving #DSA #CodingJourney #MERNstack #TechForGrowth #LinkedInLearning
To view or add a comment, sign in
-
-
NeetCode 11 | LeetCode #167 | Two Sum II – Input Array Is Sorted Practiced the two-pointer approach — efficient and intuitive for sorted arrays. This problem reinforced how understanding data properties can simplify logic and reduce complexity to O(n). #NeetCode #LeetCode #Java #Algorithms #TwoPointers #DSA #ProblemSolving #CodingJourney
To view or add a comment, sign in
-
Today’s problem: Merge Two Sorted Lists 🔗 Problem: Given two sorted linked lists, merge them into one sorted list and return it. Example: Input: list1 = [1,2,4], list2 = [1,3,4] Output: [1,1,2,3,4,4] Approach I used: ✅ Create a dummy node to simplify pointer operations. ✅ Use a pointer (tail) to build the merged list by comparing the heads of both lists. ✅ Append the smaller node each time and move forward. ✅ When one list ends, attach the remaining nodes of the other. A clean iterative solution that keeps the space usage minimal (O(1) extra space). ⚡
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