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
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
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code