Editorial
Solution walkthrough
Review the explanation, then compare the reference implementation.
Video explanation
Solution
Intuition
Choosing the first positive summand determines the second: b = n - a. With the small input bound, testing these choices directly is enough, provided both decimal representations avoid the digit zero.
Approach
Try a from one through n - 1, keeping b positive automatically. Convert both numbers to decimal strings and return the first pair whose strings contain no 0. Every positive two-part decomposition appears in this scan, and the problem guarantees a valid pair exists. The task accepts any such pair, so there is no need to continue after a match.
class Solution:
def getNoZeroIntegers(self, n: int) -> List[int]:
for a in range(1, n):
# if a + b = n, b = n - a
b = n - a
if not '0' in str(a) and not '0' in str(b):
return [a, b]Complexity analysis
In the worst case the loop tests O(n) candidates, and each decimal zero check examines O(log n) digits. Time is O(n log n) and transient auxiliary space is O(log n) for converted strings.
