Learning DSA with JavaScript: Common Pitfalls and Lessons Learned

I started learning DSA this week. No fancy roadmap, no 6-month plan — just me, JavaScript, and a lot of wrong answers on GFG. Here's what week 1 actually looked like: 🔍 Subset of an array — looks simple until it isn't I thought using a Set was the smart move. Turns out Set only tells you IF a value exists, not HOW MANY times. So when b had duplicate elements that a couldn't cover, my code happily returned true. Wrong. Switched to a frequency map — count occurrences in a, then consume them while checking b. That fixed it. 🐛 The bug that made me stare at my screen for 20 minutes Wrote j > a.length instead of j < a.length in my inner for loop. One character. The loop never ran even once. found stayed false. Everything returned false. I thought my whole logic was broken — it was just a >. 💡 Why does the `found` variable even exist? I kept wondering why I couldn't just check the condition after the inner loop. Then it clicked — the inner loop runs many times, but the outer loop needs one final answer: did we find it or not? found is just a message passed from the inner loop to the outer loop. Simple, but it took me a while. 🔄 Array rotation Left rotation — save first element, shift everything left, place it at the end. Right rotation — save last element, shift everything right, place it at the start. Looks obvious now. Wasn't at first. 📌 1-based vs 0-based indexing on GFG Spent way too long wondering why my correct logic was giving wrong answers. GFG arrays start at index 1, not 0. So instead of arr[i] === i, you need arr[i] === i + 1. One line change, completely different results. 📦 Queue using an array Front pointer, rear pointer, size counter. enqueue moves rear forward, dequeue moves front forward. When size hits 0 — reset both to -1. It finally makes sense why we need all three. None of this came easy. But every bug I fixed actually taught me something. If you're also starting DSA and feeling lost — that's normal. The bugs are part of it. What was the first DSA bug that made you question everything? 👇 #DSA #JavaScript #CodingJourney #LearnToCode #DataStructures #Algorithms #GeeksForGeeks #100DaysOfCode #ProgrammingLife #BeginnerCoder #WebDevelopment #CodeNewbie #ProblemSolving #TechLearning

Consistency matters!! Without roadmap & plans how consistency is possible?

To view or add a comment, sign in

Explore content categories