We use cookies (including Google cookies) to personalize ads and analyze traffic. By continuing to use our site, you accept our Privacy Policy.

Convert Integer to the Sum of Two No-Zero Integers

Difficulty: Easy


Problem Description

Given an integer n, return a list of two integers [a, b] where both a and b are positive integers that do not contain any digit '0' in their decimal representation, and a + b = n.


Key Insights

  • A "No-Zero integer" is defined as a positive integer that does not contain the digit '0'.
  • The problem requires finding two integers that sum to the given number n while satisfying the no-zero condition.
  • Since n is guaranteed to be at least 2, there are always valid pairs of integers to be found.
  • A straightforward approach is to iterate through possible values of a and compute b as n - a, checking for the no-zero condition.

Space and Time Complexity

Time Complexity: O(n) - In the worst case, we may need to check all integers up to n. Space Complexity: O(1) - We are using a constant amount of space for storing the result.


Solution

The solution involves iterating through integers starting from 1. For each integer a, we calculate b as n - a. We then check if both a and b are no-zero integers. The algorithm will stop when a valid pair is found. This approach is efficient given the constraints.


Code Solutions

def get_no_zero_integers(n):
    for a in range(1, n):
        b = n - a
        if '0' not in str(a) and '0' not in str(b):
            return [a, b]
← Back to All Questions