Skip to main content
Back to problems
#1689
Medium Algorithms

Partitioning into minimum number of deci binary numbers

String Greedy
90.3% acceptance
Feb 25, 2026
2783
1538
A decimal number is called deci-binary if each digit is 0 or 1. Given a string n, return the minimum number of positive deci-binary numbers needed that sum up to n.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn min_partitions(n: String) -> i32 {
    // The answer is the maximum digit in n
    n.bytes().map(|b| (b - b'0') as i32).max().unwrap_or(0)
  }
}