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;
} TCP DSA 351
TCP DSA 75 TCP DSA 150 Top 351 DSA Questions Top 351 DSA Questions Tracker 🎯 Interview Preparation Top 351 DSA Questions Track your progress, add notes, count revisions, and find which companies ask each problem. 351 Total Easy: 102 Medium: 182 Hard: 67 10 Topics Problems Solved 0 / 351 Easy: 0/102 Medium: 0/182 Hard: 0/67…
