Fairly straightforward, the problem wants us to find the sum of the array elements but before calculating, the elements must be “encrypted.” As per their definition, a number is encrypted if all the digits in the number are replaced by the maximum digit in that number.
Code:
Python3
class Solution:
def sumOfEncryptedInt(self, nums: List[int]) -> int:
ret = 0
for n in nums:
ret += int(max(str(n)) * len(str(n)))
return retBig O Analysis
- Runtime
The runtime complexity here is
O(N * M)where N = length of listnumsand M = length of numbernums[i]. - Memory Constant space! Since we don’t use any extra data structure.
— A