Ctrl K

A Sum Without Zeros

Easy
Call a positive integer *zero-free* if its decimal notation contains no digit 0. For example, 7 and 389 are zero-free, while 10 and 204 are not. You are given an integer total. Split it into two zero-free parts a and b with a + b = total, and return the list [a, b]. There may be several such pairs; return the one with the smallest a. At least one pair is guaranteed to exist.
Example 1
total=10 → [1, 9]

The pair [1, 9]: neither 1 nor 9 has a zero, and no first part can be smaller.

Example 2
total=100 → [1, 99]

1 + 99 = 100, and neither number has a zero.

Example 3
total=110 → [11, 99]

Pairs [1, 109] up to [10, 100] fail because one of the numbers contains a zero. The first good one is [11, 99].

Constraints
  • 2 ≤ total ≤ 10⁵
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Number That Reads Both Ways EasyValue of a Roman Numeral EasyAdd One to a Digit Array EasySum of Binary Strings EasyWhole Square Root Easy
loading Python…
Input
total=10
Expected
[1, 9]

Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.