Easy to understand || C++ || Faster
\nclass Solution {\npublic:\n    int toint(string x){\n        int I=0;\n        for(int i=0; i<x.size(); i++)\n            I+=x[i]-48;\n        return I;\n    
```\nclass Solution {\npublic:\n    int toint(string x){\n        int I=0;\n        for(int i=0; i<x.size(); i++)\n            I+=x[i]-48;\n        return I;\n    }\n    string digitSum(string s, int k) {\n        while(s.size()>k){\n            string temp="", x="";\n            for(int i=0; i<s.size();i++){\n                if((i+1)%k==0){\n                    x+=s[i];\n                    temp+=to_string(toint(x));\n                    x="";\n                }\n                else\n                    x+=s[i];\n            }\n            if(x.size())\n                temp+=to_string(toint(x));\n            s=temp;\n        }\n        return s;\n    }\n};\n// Please upvote if its helpful to you! \n```
['String', 'C']