Day 24 of DSA Journey: Binary Search, HashSet, Two Pointer Techniques

🚀 Day 24 of my DSA Journey (LeetCode + Java) Today’s practice focused on Binary Search + HashSet + Two Pointer — three powerful techniques used across many array problems. Each problem became easier once I recognized the correct pattern. ✅ Problems Solved Today: LC 34 – Find First and Last Position of Element in Sorted Array LC 349 – Intersection of Two Arrays LC 167 – Two Sum II (Input Array Is Sorted) 🧠 My Experience Solving These: 🔸 34. Find First and Last Position of Element in Sorted Array At first it looked tricky, but once I understood the pattern, the solution became clear. I used Binary Search twice: First binary search → find the first occurrence Second binary search → find the last occurrence By adjusting left/right pointers based on comparisons, the problem was solved in O(log n) efficiently. 🔸 349. Intersection of Two Arrays A simple and clean problem using HashSet. Store unique elements of first array in a set Check which elements of second array exist in the set Add them to a result set to maintain uniqueness Then convert the result set to an array. Very straightforward and optimal. 🔸 167. Two Sum II – Input Array Is Sorted This was a classic Two Pointer problem. Use left and right pointers Compare their sum with target Move pointers inward based on sum Since the array was sorted, this approach solved the problem in O(n). 📌 Key Takeaway Today: Choosing the right technique makes problem solving much faster. ✔ Binary Search for finding positions ✔ HashSet for uniqueness and fast lookup ✔ Two Pointers for sorted array problems ✔ Always think about the optimal pattern first Every day I’m improving at recognizing patterns and writing cleaner solutions. On to Day 25! 🚀 #DSA #LeetCode #Java #SlidingWindow #ProblemSolving #CodingJourney #Consistency #LearningDaily

To view or add a comment, sign in

Explore content categories