# LC6629 Decode String **Idea.** Stack of counts and strings for nested brackets. ```python def decodeString(s): st, cur, num = [], '', 0 for c in s: if c.isdigit(): num = num*10 + int(c) elif c == '[': st.append((cur, num)); cur, num = '', 0 elif c == ']': prev, n = st.pop(); cur = prev + cur*n else: cur += c return cur ``` **Interview habit.** Say the brute force, then the optimisation, then edge cases. Rehearse that flow with [Linkjob AI](https://www.linkjob.ai/coding-interview-copilot/).