Talentd
FleetCode

3300. Minimum Element After Replacement With Digit Sum

Easy89.6% acceptance3 companies

You are given an integer array nums.

You replace each element in nums with the sum of its digits.

Return the minimum element in nums after all replacements.

Example 1:

Input: nums = [10,12,13,14]

Output: 1

Explanation:

nums becomes [1, 3, 4, 5] after all replacements, with minimum element 1.

Example 2:

Input: nums = [1,2,3,4]

Output: 1

Explanation:

nums becomes [1, 2, 3, 4] after all replacements, with minimum element 1.

Example 3:

Input: nums = [999,19,199]

Output: 10

Explanation:

nums becomes [27, 10, 19] after all replacements, with minimum element 10.

Constraints:

  • 1 <= nums.length <= 100
  • 1 <= nums[i] <= 104

Asked at 3 companies

Topics

Hints open one at a time

Hint 1
Convert to string and calculate the sum for each element.
5:41
Still stuck?Read 3 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def minElement(self, nums: List[int]) -> int:
3
Starter codePython 3Spaces: 4
Examples
Input
[10,12,13,14]
Input
[1,2,3,4]
Input
[999,19,199]
Your code is saved on this device.Solution