© 2026 Hedgehog Software, LLC
public class DecodeString { public string StringDecode(string s) { var stkChar = new Stack<char>(); var stkDigit = new Stack<int>(); int count = 0; string recorded = ""; string currStr = ""; for (int i = 0; i < s.Length; i++) { if (Char.IsDigit(s[i])) { count = count * 10 + s[i] - '0'; Console.WriteLine($"it is a digit, report me {count}"); } else if (s[i] == '[') { stkChar.Push(s[i]); stkDigit.Push(count); count = 0; Console.WriteLine("please keep me " + currStr); recorded = currStr; currStr = ""; Console.WriteLine($"currStr after opening bracket {currStr}"); } else if (s[i] == ']') { int poppedCount = stkDigit.Pop(); //char poppedChar = stkChar.Pop(); string decoded = currStr; for (int j = 1; j < poppedCount; j++) { decoded += currStr; } Console.WriteLine($"what is decoded {decoded}"); currStr = decoded; // Update currStr Console.WriteLine($"currStr after closing bracket {currStr}"); } else { currStr += s[i]; } } return recorded + currStr; } }