Day 16 of My Daily DSA Challenge Today I solved the "3Sum" problem. This problem helped me strengthen my understanding of sorting combined with the two-pointer technique. Instead of checking every possible triplet, I learned how sorting enables smarter traversal and reduces unnecessary comparisons. Key learnings: Sorting can simplify complex search problems. Two pointers can reduce brute force solutions from cubic time to quadratic time. Handling duplicates correctly is crucial for accurate results. Each problem is improving my logical thinking and making me more comfortable with pattern-based problem solving. Staying consistent is proving to be the biggest advantage in this journey. #DSA #Java #ProblemSolving #CodingJourney #Consistency
Strengthening DSA with Sorting and Two-Pointer Technique
More Relevant Posts
-
🚀 Day 21 of solving DSA problems 🧠 Problem: Longest Consecutive Sequence Today I solved a problem where we must find the length of the longest sequence of consecutive numbers in an unsorted array — in O(n) time. 💡 Key Insight: Instead of sorting, we store elements in a HashSet and only start counting when a number has no previous consecutive element (num - 1 not present). 📌 Pattern Learned: 👉 Sequence detection using Hashing Use a set for O(1) lookup and avoid unnecessary repeated checks. ⏱ Complexity: Time → O(n) Space → O(n) 🔥 Lesson: Sometimes the optimal solution doesn’t involve sorting — smart data structures can reduce time complexity drastically. #DSA #Java #ProblemSolving #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
🚀 Day 9/30 – DSA Consistency Journey 🔎 Problem 52: LeetCode 2529 – Maximum Count of Positive Integer and Negative Integer Today I solved an interesting problem that looks simple but becomes powerful when optimized correctly using Binary Search 💡 🧠 Problem Summary Given a sorted array (non-decreasing order), return the maximum between: Number of positive integers Number of negative integers ⚠️ Note: 0 is neither positive nor negative. 💡 Key Insight Since the array is already sorted, we can avoid linear traversal and solve it in O(log n) time. Instead of counting manually, I used the Lower Bound (Binary Search) technique: ✔ First index of 0 → gives count of negative numbers ✔ First index of 1 → helps calculate positive numbers Then simply return the maximum of both counts. 👨💻 Approach Used Created a reusable leftmost() function Applied binary search to find boundary positions Calculated counts using index math Time Complexity: O(log n) Space Complexity: O(1) 📌 What I Practiced Today ✔ Binary Search Optimization ✔ Lower Bound Concept ✔ Boundary Handling ✔ Writing Cleaner, Efficient Code 📊 Progress Update: ✅ 52 Problems Completed 📅 Day 9 of 30 Days DSA Challenge Every day sharpening problem-solving skills and strengthening fundamentals 🚀 Consistency > Motivation 💪 #Day9 #DSA #Java #BinarySearch #LeetCode #ProblemSolving #InterviewPrep #CodingJourney #Consistency
To view or add a comment, sign in
-
-
🔥 Day 353 – Daily DSA Challenge! 🔥 Problem: 🔍 Single Element in a Sorted Array Given a sorted array where every element appears twice except one, find that single element in O(log n) time. 💡 Key Insight — Binary Search on Pairs In a perfect paired array: Pairs start at even indices Pattern breaks at the single element We use binary search to detect where this pattern breaks. 🧠 Core Observation Before the single element: pairs → (even, odd) After the single element: pairs shift → (odd, even) So we normalize mid: if mid is odd → make it even ⚡ Algorithm Logic ✅ Find mid ✅ Make mid even ✅ Compare: If nums[mid] == nums[mid+1] → move right Else → move left This narrows down to the single element. ⚙️ Complexity ✅ Time Complexity: O(log n) ✅ Space Complexity: O(1) 💬 Challenge for you 1️⃣ Why do we force mid to be even? 2️⃣ How would you solve this using XOR in O(n)? 3️⃣ What if elements appear thrice except one? #DSA #Day353 #LeetCode #BinarySearch #Arrays #Optimization #Java #ProblemSolving #KeepCoding
To view or add a comment, sign in
-
-
🚀 Day 22 of solving DSA problems 🧠 Problem: Set Matrix Zeroes (2D Array) Today I worked on a matrix problem where if any element is 0, its entire row and column must be set to 0 — and the catch was to do it in-place. 💡 Key Insight: Instead of modifying the matrix immediately (which breaks future checks), we first mark which rows and columns should become zero, then update them later. 📌 Pattern Learned: 👉 Mark first → Modify later This pattern is useful whenever changing data early can affect future logic. ⏱ Complexity: Time → O(m × n) Space → O(1) (optimized approach) 🔥 Lesson: Many matrix problems test careful thinking more than coding difficulty. Handling indices and update order correctly is the real challenge. #DSA #Java #CodingJourney #ProblemSolving #LearningInPublic
To view or add a comment, sign in
-
-
Day 18 of My Daily DSA Challenge Today I solved the "Merge Two Sorted Lists" problem. This problem strengthened my understanding of linked list manipulation and recursive thinking. The main challenge was carefully comparing nodes and attaching them in sorted order while maintaining proper references between nodes. Key learnings: Recursive solutions can make linked list problems more intuitive. Base cases are critical in recursion to avoid infinite calls. Handling null conditions correctly prevents runtime errors. Problems like this remind me that data structures are not just about code syntax, but about understanding how data moves and connects internally. Consistency is slowly building stronger logic and confidence with each passing day. #DSA #Java #LinkedList #ProblemSolving #CodingJourney #Consistency
To view or add a comment, sign in
-
Day 21/100 of DSA , (Arrays) 🚀Today I tackled the “Set Matrix Zeroes” problem At first, the brute force approach is tempting: traverse the matrix and use extra space to track zeros. Instead, I focused on the logic behind minimizing space: 🔹 Using the first row and first column as markers 🔹 Traversing carefully to avoid overwriting important values 🔹 Setting zeros in-place without extra arrays This problem is a reminder that optimization is not just about speed, but also about smart memory usage. 💡 Key takeaways: Think about what can be reused instead of creating new structures Always consider edge cases in 2D arrays Small logical adjustments make a big difference in performance Another step forward in mastering DSA fundamentals and improving problem-solving efficiency. 🚀 #DSA #Java #ProblemSolving #MatrixProblems #CodingJourney #InterviewPreparation #OptimizedCode
To view or add a comment, sign in
-
-
Mastering DSA Pattern by Pattern — Starting with Two Pointers 🚀 Instead of solving random problems, I’ve decided to rebuild my fundamentals with a structured approach. 📌 Pattern 1: Two Pointers Technique Why this pattern matters: • Extremely useful in sorted arrays • Common in pair-sum and palindrome problems • Helps reduce time complexity from O(n²) to O(n) • Builds strong control over index movement and edge cases What I’m focusing on: ✔ Opposite direction pointers (left ↔ right) ✔ Slow & Fast pointer technique ✔ Handling duplicates correctly ✔ Avoiding infinite loops ✔ Writing clean Java implementations Plan: Solve 25 focused problems in the next 2 days and document key learnings. Big realization: Most DSA problems are not about complex logic — they’re about recognizing patterns early. Rebuilding step by step. #DSA #Java #TwoPointers #SoftwareEngineering #CodingJourney #TechCareer
To view or add a comment, sign in
-
Day 3 — Pattern-Based DSA Practice Continuing to learn and build in public while solving problems pattern by pattern. Today’s focus: Array-Based Problem Solving Problems solved: • Best Time to Buy and Sell Stock • Count Occurrences • Majority Element • Maximum Product Subarray • Merge Intervals • Missing Number • Move Zeroes • Rotation • Sort Colors • Two Sum Key learning: Many array problems are not about complex logic, but about choosing the right approach for the situation. Some required: • greedy thinking • in-place manipulation • understanding patterns like two pointers Realizing that improving in DSA is less about solving more problems and more about understanding why a particular approach works. Trying to focus on pattern recognition and clean implementation. #DSA #Arrays #ProblemSolving #LearningInPublic #Java #CodingJourney
To view or add a comment, sign in
-
Day 16 of DSA practice 🚀 (Binary Search Patterns) Today I worked on two interesting problems that strengthened my binary search intuition in different ways: 🆕 #1011 – Capacity To Ship Packages Within D Days 🆕 #162 – Find Peak Element Problem #1011 was another solid example of binary search on the answer space — defining the minimum capacity and validating it with a feasibility check. Problem #162 reinforced how binary search can be applied even when the array isn’t fully sorted, as long as we can eliminate half the search space logically. The more I practice binary search, the more I realize it’s about recognizing patterns — not memorizing templates 🔥 #DSA #LeetCode #BinarySearch #ProblemSolving #Java #Consistency #LearningInPublic #100DaysOfCode
To view or add a comment, sign in
-
Day 23 - DSA Practice Solved “Reverse Pairs” today using the Merge Sort approach to optimize the brute force solution. When problems involve counting pairs with conditions across the array, Divide & Conquer (Merge Sort technique) can reduce time complexity from O(n²) → O(n log n). Every problem is a small step toward mastering problem solving and system thinking. #LeetCode #DSA #ProblemSolving #Java #CodingJourney #MergeSort #LearningInPublic
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