string decodedString(string &s) {
// code here
stack<char> st;
string ans;
for(int i=0;i<s.size(); i++) {
if(s[i] != ']') st.push(s[i]);
else {
string temp;
while(!st.empty() && st.top() != '[') {
temp.push_back(st.top());
st.pop();
}
reverse(temp.begin(), temp.end());
st.pop();
string dig;
while(!st.empty() && isdigit(st.top())) {
dig.push_back(st.top());
st.pop();
}
reverse(dig.begin(), dig.end());
string word;
for(int j=0; j<stoi(dig); j++) {
word.append(temp);
}
for(char c:word)
st.push(c);
}
}
while(!st.empty()) {
ans.push_back(st.top());
st.pop();
}
reverse(ans.begin(), ans.end());
return ans;
}