Find the Sum of Encrypted Integers - Problem

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.

Input & Output

Example 1 — Basic Encryption
$ Input: nums = [1,2,3]
Output: 6
💡 Note: encrypt(1) = 1, encrypt(2) = 2, encrypt(3) = 3. Sum = 1 + 2 + 3 = 6
Example 2 — Multi-digit Numbers
$ Input: nums = [523,213]
Output: 888
💡 Note: encrypt(523) = 555 (max digit 5), encrypt(213) = 333 (max digit 3). Sum = 555 + 333 = 888
Example 3 — Same Digits
$ Input: nums = [999]
Output: 999
💡 Note: encrypt(999) = 999 (all digits are 9). Sum = 999

Constraints

  • 1 ≤ nums.length ≤ 50
  • 1 ≤ nums[i] ≤ 1000

Visualization

Tap to expand
Encrypt and Sum: [523, 213] → [555, 333] → 888Step 1: Input Array523213Step 2: Encrypt Each Number555max digit: 5333max digit: 3Step 3: Sum Results555 + 333 = 888
Understanding the Visualization
1
Input
Array of positive integers
2
Encrypt
Replace each digit with max digit in that number
3
Sum
Add all encrypted numbers together
Key Takeaway
🎯 Key Insight: Find the maximum digit in each number and repeat it to create the encrypted form
Asked in
Google 15 Amazon 12
12.5K Views
Medium Frequency
~10 min Avg. Time
340 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen