Talentd
FleetCode

1317. Convert Integer to the Sum of Two No-Zero Integers

Easy59.1% acceptance4 companies

No-Zero integer is a positive integer that does not contain any 0 in its decimal representation.

Given an integer n, return a list of two integers [a, b] where:

  • a and b are No-Zero integers.
  • a + b = n

The test cases are generated so that there is at least one valid solution. If there are many valid solutions, you can return any of them.

Example 1:

Input: n = 2
Output: [1,1]
Explanation: Let a = 1 and b = 1.
Both a and b are no-zero integers, and a + b = 2 = n.

Example 2:

Input: n = 11
Output: [2,9]
Explanation: Let a = 2 and b = 9.
Both a and b are no-zero integers, and a + b = 11 = n.
Note that there are other valid answers as [8, 3] that can be accepted.

Constraints:

  • 2 <= n <= 104

Asked at 4 companies

Topics

Hints open one at a time

Hint 1
Loop through all elements from 1 to n.
Hint 2
Choose A = i and B = n - i then check if A and B are both No-Zero integers.
2:41
Still stuck?Read 4 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def getNoZeroIntegers(self, n: int) -> List[int]:
3
Starter codePython 3Spaces: 4
Examples
Input
2
Input
11
Your code is saved on this device.Solution