JAVA (StringBuilder and String) Commented
Using String :\nRuntime: 6 ms\nMemory Usage: 40.6 MB\n\nclass Solution {\n    public String digitSum(String s, int k) {\n        int len = s.length();\n        
Using String :\nRuntime: 6 ms\nMemory Usage: 40.6 MB\n```\nclass Solution {\n    public String digitSum(String s, int k) {\n        int len = s.length();\n        String ans = s; //making a copy of string s\n        while(ans.length() > k) {\n            String dummy = ""; // this will store the string after a round\n            int i = 0;\n            for(i = 0; i < ans.length(); i+=k) {\n                int sum = 0;\n                for(int j = 0; j < k && (j+i) < ans.length(); j++) {\n                    sum += ans.charAt(i+j)-\'0\';\n                }\n                dummy += sum+""; //adding the result to the string\n            }\n            ans = dummy; //adding modified value to the answer\n        }\n        return ans;\n    }\n}\n```\n\nUsing StringBuilder :\nRuntime: 1 ms\nMemory Usage: 40.7 MB\n\n```\nclass Solution {\n    public String digitSum(String s, int k) {\n        StringBuilder ans = new StringBuilder(s);\n        int len = s.length();\n        while(ans.length() > k) {\n            StringBuilder dummy = new StringBuilder();\n            int i = 0;\n            for(i = 0; i < ans.length(); i+=k) {\n                int sum = 0;\n                for(int j = 0; j < k && (j+i) < ans.length(); j++) {\n                    sum += ans.charAt(i+j)-\'0\';\n                }\n                dummy.append(sum+"");\n            }\n            ans = dummy;\n        }\n        return ans.toString();\n    }\n}\n```
['String', 'Java']