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
Big O Analysis
-
Runtime
The runtime complexity here is
O(N * M)
where N = length of listnums
and M = length of numbernums[i]
. -
Memory
Constant space! Since we don’t use any extra data structure.
— A