Day 11/30 – 3Sum Closest 🚀 Problem: Find three numbers whose sum is closest to a given target. Approach: • Sort the array • Fix one element • Use Two Pointers • Track minimum difference using Math.abs() Key Idea: Instead of finding exact zero (like 3Sum), minimize the distance from target. Time Complexity: O(n²) Space Complexity: O(1) #30DaysOfCode #Java #DSA #TwoPointers #InterviewPrep
3Sum Closest Problem Solution with Two Pointers
More Relevant Posts
-
🚀100 Days of Code - Day 10 Today I worked on a classic Regular Expression Matching problem. Given a string s and a pattern p, determine if the entire string matches the pattern. The pattern supports: • . → matches any single character • * → matches zero or more of the preceding element Example: s = "ab" p = ".*" Output → true This problem is a great exercise in Dynamic Programming and pattern matching concepts. #Java #Algorithms #DataStructures #ProblemSolving #CodingPractice
To view or add a comment, sign in
-
-
𝗬𝗼𝘂 𝗵𝗮𝘃𝗲 𝗯𝗲𝗲𝗻 𝘂𝘀𝗶𝗻𝗴 𝗕𝗶𝗻𝗮𝗿𝘆 𝗦𝗲𝗮𝗿𝗰𝗵 𝘄𝗿𝗼𝗻𝗴. It is not just for sorted arrays. The real definition — "Eliminate HALF the search space with each decision." That one shift in thinking unlocks 20+ LeetCode problems. Swipe to see the template, live code, and 7 problems you can now solve with one pattern. 👇 Save this. 🔖 #DSA #BinarySearch #Java #LeetCode #CodingInterview #DebugWithPurpose
To view or add a comment, sign in
-
Leetcode Problem || Number of Steps to Reduce a Number in Binary Representation to One(1404)🚀 Today I solved a binary manipulation problem where we must: If number is even → divide by 2 If odd → add 1 Count steps until number becomes 1 💡 Learned: How to simulate binary addition using carry Avoid integer overflow Optimize string-based numeric problems #Java #DSA #BitManipulation #LeetCode #ProblemSolving
To view or add a comment, sign in
-
-
Day: 53/365 📌 LeetCode POTD: Concatenation of Consecutive Binary Numbers Medium Key takeaways/Learnings from this problem: 1. This problem nicely mixes math + bit manipulation, especially understanding how many bits each number contributes. 2. Instead of literally concatenating strings, shifting the current result left by the bit-length is way more efficient. 3. It reinforces the idea that log2 helps you find bit length quickly for each number. 4. Big takeaway: always think in terms of binary operations when the problem screams “binary” — strings are usually a trap here. #POTD #365DaysOfCode #DSA #Java #ProblemSolving #LearningInPublic #Consistency 🥷
To view or add a comment, sign in
-
-
Day 26 – Find Peak Element Worked on finding a peak element using the “binary search on slope” technique. Key Learning: By comparing nums[mid] with nums[mid + 1], I determined the direction of the peak and narrowed the range in logarithmic time. #DSA #BinarySearch #LeetCode #Java #CodingPractice
To view or add a comment, sign in
-
-
Stop writing code that “just works.” Day 45 / 100 Days of DSA Problem: Find a pair from two arrays whose sum is closest to a target. First approach: Nested loops. Better approach: Two pointers (since arrays are sorted). Move intelligently based on the sum. Time Complexity: O(n + m). Same answer. Smarter thinking. Day 45 lesson: Don’t stop at “it works.” Push for optimal. #Day45 #100DaysOfCode #DSA #Java #ProblemSolving
To view or add a comment, sign in
-
-
🚀 Day 6 – DSA Practice Solved Remove Duplicates from Sorted Array today. 📌 Problem: Given a sorted array, remove duplicates in-place such that each element appears only once and return the new length. 💡 Insight: Use the two-pointer approach — one pointer tracks unique elements, while the other scans the array to update values in-place. ⏱ Time Complexity: O(n) 📦 Space Complexity: O(1) Strengthening my understanding of in-place array manipulation and pointer techniques. #Java #DSA #LeetCode #TwoPointers #CodingInterview
To view or add a comment, sign in
-
-
✅ LeetCode Top Interview 150 – Day 65 Today I solved the Same Tree problem where I had to check whether two binary trees are structurally identical and have the same node values. Key Idea : Compare both trees node by node using recursion. If both nodes are null → trees are same. If one node is null and the other is not → trees are different. If values are different → return false. Recursively compare: Left subtree of both trees Right subtree of both trees If all comparisons match, the trees are considered identical. #DSA #Leetcode #Java #BinaryTree #Day66
To view or add a comment, sign in
-
-
Day 35 – Plus One Worked on a problem where a large integer is represented as an array of digits, and the task was to increment the number by one. Key Learnings: Traversing arrays from right to left to simulate digit addition Handling carry when a digit becomes 10 Managing edge cases where all digits are 9 by creating a new array #DSA #Java #Arrays #ProblemSolving #CodingPractice #LeetCode
To view or add a comment, sign in
-
-
Day 46 - String Compression Used a two pointer approach to group consecutive characters and write compressed results directly into the input array. If a character repeats, its count is converted to digits and appended sequentially. Time Complexity: O(n) #Day46 #LeetCode #Java #Algorithms #TwoPointers #DSA
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