java solution
Iterative:\n\n\tclass Solution {\n    public String digitSum(String s, int k) {\n        if(s.length() <= k)\n            return s;\n        \n        while(s.l
Iterative:\n\n\tclass Solution {\n    public String digitSum(String s, int k) {\n        if(s.length() <= k)\n            return s;\n        \n        while(s.length() > k){\n            String temp = "";\n            for(int i = 0; i < s.length(); i += k){\n                int curSum = 0;\n                for(int j = 0; j < k && (j + i) < s.length(); j++){\n                    curSum += s.charAt(i + j) - \'0\';\n                }\n                temp += curSum +"";\n            }\n            s = temp;\n        }\n        \n        return s;\n    }\n\t}\n\nRecursive:\n\n\tclass Solution {\n    public String digitSum(String s, int k) {\n       \n        while(s.length() > k){\n            s = roundTrip(s, k);\n        }\n        return s;\n    }\n    \n    public String roundTrip(String s, int k){\n        int i = 0, j = 0, currSum = 0;\n        String ans = "";\n        for(;i < s.length();){\n            while(j < k && i < s.length()){\n                currSum += s.charAt(i) - \'0\';\n                i++;\n                j++;\n            }\n            ans += currSum;\n            j = 0; \n            currSum = 0;\n        }\n        \n        return ans;\n    }\n\t}
['Java']