Solved 4 DSA problems with DFS, 3-pointers, Sliding Window & Greedy Algorithms

Day 1 of problem solving: 🚀 Solved 4 interesting DSA problems today — sharing quick approaches + core logic 👇 1️⃣ Detect Cycles in 2D Grid Used DFS + parent tracking. The key idea is to traverse only same-valued adjacent cells and detect whether we revisit an already visited cell that is not the immediate parent. 🔹 Algorithm: Graph Traversal (DFS) 🔹 Logic: visited[][] + previous cell coordinates 2️⃣ Common Elements in 3 Sorted Arrays Applied the 3-pointer technique. Since all arrays are sorted, we move the pointer pointing to the smallest value until all three values match. 🔹 Algorithm: Two/Three Pointers 🔹 Logic: linear scan in O(n1 + n2 + n3) 3️⃣ Smallest Window Containing 0, 1 and 2 Solved using the Sliding Window approach. Expand the right pointer until the window contains all 3 digits, then shrink from the left to find the minimum valid window. 🔹 Algorithm: Sliding Window 🔹 Logic: frequency count + two pointers 4️⃣ Halloumi Boxes (Codeforces) A beautiful observation-based problem. If k = 1, no movement is possible, so the array must already be sorted. If k > 1, adjacent swaps become possible through reversal, meaning any array can be sorted. 🔹 Algorithm: Greedy / Observation 🔹 Logic: reversal length property 💡 Today’s takeaway: Not every problem needs heavy coding — sometimes the strongest solution comes from the right observation and choosing the correct algorithmic pattern. #DSA #Java #LeetCode #Codeforces #ProblemSolving #Algorithms #DataStructures #CodingInterview #SoftwareEngineer #100DaysOfCode Follow for more problem solving content and stay updated 🚀

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories