Decoding Strings with Stack Approach

Day 44 of 365 Days of code 😵💫 Qn 1) Decode String approach: stack took me a while to solve, but the problem was worth the time taken. 1)keep on pushing the characters into the stack until you encounter a " ] " closing bracket. 2) if a closing bracket is encountered initialize an empty string and keep popping the elements and add it to a string until a open square bracket is found on top of the stack 3) If the top element in the stack is an integer, multiply the integer with the string, and append it to the string 4) elif the top element is a string add the string to the top element 5) else append the string 6) reverse the stack, pop the reversed stack and add it to string res 7) return res gn #365daysOfCode #NeetCode  #leetcode  #DSA  #python #LeetCode #ProblemSolving  #Algorithms #365dayschallenge

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories