🚀 A Small Stack Problem That Changed My Thinking "When I first learned Stack, I thought I understood it." 🚀 What I Learned from Solving “Decode String” (LeetCode 394) Before solving this problem, my understanding of Stack was very basic. I thought: 👉 Just push everything into the stack — characters, numbers, symbols — and then use pop() and peek() whenever needed. But this question changed my thinking. 💡 Key Learnings: ✅ Stack is not about pushing everything blindly. We should push elements only until a specific condition is met. In this problem, we push elements into the stack until we encounter ]. Only then do we start popping and processing. This showed me a clear pattern-based stack usage. ✅ Conditional stack processing is important. Instead of random pop/peek operations, we must: Pop until [ Extract the number before [ Repeat the substring correctly This improved my problem-solving structure. ✅ Stack does not support primitive data types directly. In Java, Stack works with objects. So we cannot directly store char or int as primitives — we need to use: Character Integer or String That clarified an important Java concept for me. ✅ Learned how and why to use String.repeat() method. If we have a string and we want to multiply it multiple times, we can use repeat(). For example: If we have: "abc" and we want it 3 times Instead of manually looping, we can write: "abc".repeat(3) Output:👉 abcabcabc Special Thanks to Hareesh Rajendran na for Clear Explanation and his Support #DataStructures #Stack #Java #LeetCode #ProblemSolving #CodingJourney
Lot more to come 🔥🔥🔥
All the best
Vishwashvar Prasanth, perfect time to lear Monotonic DS Deep dive on Monotonic Stack & Deque — one of the most frequently asked patterns in FAANG interviews. https://www.garudax.id/posts/amaan-sharif-nirban-b469041a5_dsa-monotonicstack-monotonicdeque-activity-7429023557034115072-kOsn