Problem statement

https://binarysearch.com/problems/Concatenated-Sums/

Solution

What we need to know is for each length how many numbers we have. Then we can have direct formula.

Complexity

It is O(n) for time and O(1) for space.

Code

class Solution:
    def solve(self, nums):
        return (sum(10**len(str(x)) for x in nums) + len(nums)) * sum(nums)