Given an integer n, return a list of two integers [A, B] where:
A and B are both positive integers.A + B = nA nor B contains any zero digit.If there are multiple answers, you can return any of them.
n: What is the range of input integer n? (Usually, for LeetCode problems, this would be specified, but for the sake of this problem, you can assume that n is a positive integer greater than 1).These questions help understand the constraints and requirements more clearly.
Since this is a problem requiring to avoid any digits being zero, let’s move on to the coding solution.
A from 1 to n-1. If A contains no zero digits then check if B = n - A contains no zero digits as well.Here’s the implementation of the above strategy:
def has_no_zero(n: int) -> bool:
"""Helper function to check if a number has any zero digits."""
return '0' not in str(n)
def getNoZeroIntegers(n: int) -> [int, int]:
for A in range(1, n):
B = n - A
if has_no_zero(A) and has_no_zero(B):
return [A, B]
# Example Usage
n = 101
print(getNoZeroIntegers(n)) # Example output: [2, 99] or any other valid pair
n, making the time complexity O(n).has_no_zero function runs in O(d), where d is the number of digits in n, which is O(log(n)).Overall, the time complexity is O(n * log(n)), which is efficient given the typical constraints for an integer value.
Got blindsided by a question you didn’t expect?
Spend too much time studying?
Or simply don’t have the time to go over all 3000 questions?