5-Lines Python Solution || 100% Faster || Memory less than 85%
\n\n\n### Solution: TC O((n/k)\n) / SC O(n)\n\nclass Solution:\n    def digitSum(self, s: str, k: int) -> str:\n        while len(s)>k:\n            tmp=\'\'\n 
![image](https://assets.leetcode.com/users/images/7116de29-f9e8-4941-a72f-528d52cbef18_1650204904.767027.png)\n\n\n### ***Solution: TC O((n/k)\\*n) / SC O(n)***\n```\nclass Solution:\n    def digitSum(self, s: str, k: int) -> str:\n        while len(s)>k:\n            tmp=\'\'\n            for i in range(0,len(s),k): tmp+=str(sum([int(d) for d in s[i:i+k]]))\n            s=tmp\n        return s\n```\n\n-----------------\n### ***One-Line Version:***\n```\nclass Solution:\n    def digitSum(self, s: str, k: int) -> str:\n        return self.digitSum(\'\'.join(str(sum(int(d) for d in s[i:i+k])) for i in range(0,len(s),k)), k) if len(s) > k else s\n```\n-------------------\n***----- Taha Choura -----***\n*taha.choura@outlook.com*\n
['Python', 'Python3']