Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count No-Zero Pairs That Sum to N

XPChallenge Points: 30
levelLevel: Hard

A no-zero integer is a positive integer whose decimal representation contains no digit 0.
Given an integer n, count the number of ordered pairs (a, b) such that:

  • a and b are no-zero integers, and

  • a + b = n.

Return the count as an integer.

Example 1:

Input: n = 5

Output: 4

Explanation:

Valid ordered pairs: (1,4), (2,3), (3,2), (4,1).

Example 2:

Input: n = 12

Output: 9

Explanation:

Invalid pairs involve a 10. Valid ordered pairs: (1,11), (3,9), (4,8), (5,7), (6,6), (7,5), (8,4), (9,3), (11,1) → 9 total.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result