Talentd
FleetCode

3079. Find the Sum of Encrypted Integers

Easy74.7% acceptance1 company

You are given an integer array nums containing positive integers. We define a function encrypt such that encrypt(x) replaces every digit in x with the largest digit in x. For example, encrypt(523) = 555 and encrypt(213) = 333.

Return the sum of encrypted elements.

Example 1:

Input: nums = [1,2,3]

Output: 6

Explanation: The encrypted elements are [1,2,3]. The sum of encrypted elements is 1 + 2 + 3 == 6.

Example 2:

Input: nums = [10,21,31]

Output: 66

Explanation: The encrypted elements are [11,22,33]. The sum of encrypted elements is 11 + 22 + 33 == 66.

Constraints:

  • 1 <= nums.length <= 50
  • 1 <= nums[i] <= 1000

Asked at 1 company

Topics

Hints open one at a time

Hint 1
Encrypted numbers are of the form 11…1 * maxDigit.
0:17
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def sumOfEncryptedInt(self, nums: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[1,2,3]
Input
[10,21,31]
Your code is saved on this device.Solution