a few solutions
Recursively reduce the input string s into k-sized chunks.\n\n---\n\nKotlin\n\nclass Solution {\n    fun digitSum(s: String, k: Int): String {\n        var N = 
Recursively reduce the input string `s` into `k`-sized chunks.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun digitSum(s: String, k: Int): String {\n        var N = s.length\n        if (N <= k)\n            return s\n        var f = { s: String -> s.toCharArray().map{ it.toInt() - \'0\'.toInt() }.sum()!! }\n        return digitSum(s.chunked(k).map{ f(it) }.joinToString(""), k)\n    }\n}\n```\n\n*Javascript*\n```\nlet digitSum = (s, k) => {\n    let N = s.length;\n    if (N <= k)\n        return s;\n    let A = [];\n    for (let i = 2; i <= N; ++i)\n        if (!(i % k))\n            A.push(s.substr(i - k, k));\n    let mod = N % k;\n    if (mod)\n        A.push(s.substr(N - mod, mod));\n    let f = s => _.sum(s.split(\'\').map(c => c.charCodeAt(0) - \'0\'.charCodeAt(0)));\n    return digitSum(A.map(s => f(s)).join(\'\'), k);\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def digitSum(self, s: str, k: int) -> str:\n        N = len(s)\n        if N <= k:\n            return s\n        A = [s[i:i + k] for i in range(0, N, k)]\n        f = lambda s: sum(int(c) for c in s)\n        return self.digitSum(\'\'.join([str(f(s)) for s in A]), k)\n```\n\n*Rust: this solution is based upon [BigMih\'s solution](https://leetcode.com/problems/calculate-digit-sum-of-a-string/discuss/1957505/Rust-solution)*\n```\nimpl Solution {\n    pub fn digit_sum(s: String, k: i32) -> String {\n        let k = k as usize;\n        let mut s = s;\n        while !(s.len() <= k) {\n            s = s.chars().collect::<Vec<_>>().chunks(k)\n                .map(|it| it.iter().map(|c| c.to_digit(10).unwrap()).sum::<u32>().to_string())\n                .collect::<Vec<_>>().join("");\n        }\n        return s;\n    }\n}\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VS = vector<string>;\n    string digitSum(string s, int k, VS A = {}) {\n        int N = s.size();\n        if (N <= k)\n            return s;\n        for (auto i{ 2 }; i <= N; ++i)\n            if (!(i % k))\n                A.push_back(s.substr(i - k, k));\n        int mod = N % k;\n        if (mod)\n            A.push_back(s.substr(N - mod, mod));\n        auto f = [](auto& s) {\n            return accumulate(s.begin(), s.end(), 0, [](auto t, auto c) {\n                return t + c - \'0\';\n            });\n        };\n        ostringstream os;\n        for (auto& s: A)\n            os << f(s);\n        return digitSum(os.str(), k);\n    }\n};\n```
[]