Calculate Digit Sum of a String T.C. O(n), S.C. O(1).
\nclass Solution {\npublic:\n    string digitSum(string s, int k) \n    {\n        while (s.size() > k)  // Run the loop until given string s length is greater 
```\nclass Solution {\npublic:\n    string digitSum(string s, int k) \n    {\n        while (s.size() > k)  // Run the loop until given string s length is greater than k otherwise return the string.\n        {\n            string temp = ""; // Temp variable to store the new string.\n            for (int i = 0; i < s.size(); i++)\n            {\n                int sum = 0;\n                int count = 0;\n                while (i < s.size() && count < k)  // Run the loop until count is less than k or iterator is less than the size of string.\n                {\n                    sum += s[i++] - \'0\'; // Sum up the string value\n                    count++;  // Increase the count \n                }\n                temp += to_string(sum);  // Add the obtained sum to the temp variable.\n                i--;\n            }\n            s = temp; // Update the value of main string.\n        }\n        return s; // Return the final string.\n    }\n};\n\n// Hope it will help. :)\n```
['String', 'C', 'C++']