C++ | Simulation (Iterative) | Time: O(len) | Auxiliary Space: O(len / k)
\nclass Solution {\npublic:\n    string digitSum(string s, int k) {\n        while (s.length() > k) {\n            string ret = "";\n            for (int i = 0;
```\nclass Solution {\npublic:\n    string digitSum(string s, int k) {\n        while (s.length() > k) {\n            string ret = "";\n            for (int i = 0; i < s.length(); i += k) {\n                string sub = s.substr(i, k);\n                int sum = 0;\n                for (auto c: sub) {\n                    sum += c - \'0\';\n                }\n                ret += to_string(sum);\n            }\n            s = ret;\n        }\n        return s;\n    }\n};\n```
[]