Convert Integer to the Sum of Two No-Zero Integers - Problem
No-Zero Integer Challenge

A No-Zero integer is a positive integer that doesn't contain any 0 digits in its decimal representation. For example, 123 and 789 are No-Zero integers, but 102 and 300 are not.

Given an integer n, your task is to find two No-Zero integers a and b such that:
  • Both a and b are positive No-Zero integers
  • a + b = n

Return any valid pair [a, b] as an array. The problem guarantees that at least one valid solution exists.

Examples:
n = 11[1, 10] is invalid (10 contains 0), but [2, 9] is valid
n = 1000[1, 999] works perfectly

Input & Output

example_1.py — Python
$ Input: n = 2
Output: [1, 1]
💡 Note: Both 1 and 1 are No-Zero integers, and 1 + 1 = 2
example_2.py — Python
$ Input: n = 11
Output: [2, 9]
💡 Note: We can't use [1, 10] because 10 contains a zero. [2, 9] works since both numbers have no zeros and 2 + 9 = 11
example_3.py — Python
$ Input: n = 1000
Output: [1, 999]
💡 Note: 1 and 999 are both No-Zero integers that sum to 1000. Note that 999 has no zeros despite being close to 1000

Constraints

  • 2 ≤ n ≤ 104
  • The answer is guaranteed to exist
  • Both returned integers must be positive

Visualization

Tap to expand
No-Zero Integer DecompositionProblem: Split n=11 into two no-zero integersOriginal Number11Try a = 1b = 10Invalid!10 has zeroTry a = 2b = 9Valid!No zerosSolution Found![2, 9]Key Insight: Linear Search Strategy• Start with smallest possible first number (a = 1)• Calculate complement: b = n - a• Check both numbers for zeros using string conversion• Guaranteed to find solution quickly since most small numbers have no zeros
Understanding the Visualization
1
Start Simple
Begin with the smallest possible first number (1)
2
Calculate Complement
Find what the second number must be: b = n - a
3
Validate Both
Check that neither number contains the digit 0
4
Success or Continue
Return the pair if valid, otherwise try the next number
Key Takeaway
🎯 Key Insight: Since a solution is guaranteed to exist and most small numbers don't contain zeros, a simple linear search from a=1 upward will quickly find a valid pair, making this an efficient O(n) solution in practice.
Asked in
Google 15 Amazon 12 Microsoft 8 Apple 6
67.0K Views
Medium Frequency
~12 min Avg. Time
1.9K 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