Problem

Qn - Convert Integer to the Sum of Two No-Zero Integers

Approach

Originally thought that we can randomly generate numbers and check if they are a zero integer, but then soon realised that we need a set to keep track of numbers that we have tried, that would make it in both time and space. Then realised that we can do away with the set to keep track of the numbers and just do it iteratively, from 1 all the way to n.

Complexity

  • Time:
  • Space:

Code

class Solution:
    def getNoZeroIntegers(self, n: int) -> List[int]:
        def isZeroInteger(num):
            while num:
                if not num%10: return False
                num //= 10
            return True
 
        for i in range(1,n):
            if isZeroInteger(i) and isZeroInteger(n-i): return [i,n-i]