Partitioning Into Minimum Number Of Deci-Binary Numbers

A decimal number is called deci-binary if every one of its digits is `0` or `1` and it has no leading zeros, for example `101` and `1100`. Given a string `n` that holds a positive decimal integer, return the minimum number of positive deci-binary numbers that sum to `n`.

30:00

Partitioning Into Minimum Number Of Deci-Binary Numbers
medium
Free written solution
Topics
Companies

A decimal number is called deci-binary if every one of its digits is 0 or 1 and it has no leading zeros, for example 101 and 1100. Given a string n that holds a positive decimal integer, return the minimum number of positive deci-binary numbers that sum to n.

Example 1:
Input: {"n":"32"}
Output: 3
Constraints:
  • 1≤n.length≤1051 \leq \text{n.length} \leq 10^5

  • nn consists of only digits.

  • nn does not contain any leading zeros and represents a positive integer.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":"32"}
best = 0
2 digits

9

8

7

6

5

4

3

2

1

3

2

A deci-binary number adds at most 1 to each digit position, so a digit d needs at least d of them. Find the largest digit of 32.

Variables
VariableValue
best0
DepthFunction Call
Stack empty
0/6