LeetCode Entry
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers
Min 01-strings add up to target
1689. Partitioning Into Minimum Number Of Deci-Binary Numbers medium blog post substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1284
Problem TLDR
Min 01-strings add up to target #medium
Intuition
// 279
// 101
// 101
// 11 * 7
// 2
// 7
// (2+7)
//
// 12345
// 11111
// 1111
// 111
// 11
// 1
//
// 54321
// 11111
// 1111
// 111
// 11
// 1
//
// 105
//
// 50
//
// 505
Greedy idea: take as big binary number as possible to quickly fill to target.
Approach
- max
Complexity
-
Time complexity: \(O(n)\)
-
Space complexity: \(O(1)\)
Code
// 24ms
fun minPartitions(n: String) =
n.max() - '0'
// 0ms
pub fn min_partitions(n: String) -> i32 {
(n.bytes().max().unwrap() - 48) as _
}