Partitioning Into Minimum Number Of Deci-Binary Numbers - Problem
A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. For example, 101 and 1100 are deci-binary, while 112 and 3001 are not.
Given a string n that represents a positive decimal integer, return the minimum number of positive deci-binary numbers needed so that they sum up to n.
Input & Output
Example 1 — Basic Case
$
Input:
n = "32"
›
Output:
3
💡 Note:
We can decompose 32 into three deci-binary numbers: 10 + 11 + 11 = 32. The maximum digit is 3, so we need at least 3 deci-binary numbers.
Example 2 — Single Digit
$
Input:
n = "82734"
›
Output:
8
💡 Note:
The maximum digit in 82734 is 8, so we need exactly 8 deci-binary numbers to sum up to this value.
Example 3 — All Same Digits
$
Input:
n = "27346209830709182346"
›
Output:
9
💡 Note:
Despite being a very large number, we only need 9 deci-binary numbers because the maximum digit is 9.
Constraints
- 1 ≤ n.length ≤ 105
- n consists of only digits
- n does not contain any leading zeros and represents a positive integer
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code