leetcode

Leetcode Solutions (0x6A73)
git clone https://git.pngu.org/leetcode
Log | Files | Refs | Submodules | README

commit 9605ced59cb3b7cf19d1f86616446aabbd56bac0
parent 13824fc1f6b424fe1a12a8e407db8fc467742ee3
Author: Jack Sangdahl <jack@pngu.org>
Date:   Sat, 28 Feb 2026 17:51:18 -0700

1689. partitioning into minimum number of deci-binary numbers

Diffstat:
Apartition_min_num_deci_bin_num.c | 30++++++++++++++++++++++++++++++
Apartition_min_num_deci_bin_num.py | 21+++++++++++++++++++++
2 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/partition_min_num_deci_bin_num.c b/partition_min_num_deci_bin_num.c @@ -0,0 +1,30 @@ +// 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers +#include "leetcode.h" + +/* + * 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 possible deci-binary numbers needed so + * that they sum up to 'n'. + */ + +int minPartitions(char *n) { + char max_char = '0'; + for (int i = 0; n[i] != '\0'; i++) + max_char = fmax(max_char, n[i]); + return max_char - '0'; +} + +int main() { + char *n1 = "32", *n2 = "82734", *n3 = "27346209830709182346"; + int r1 = minPartitions(n1); + int r2 = minPartitions(n2); + int r3 = minPartitions(n3); + printf("%d\n", r1); // expect: 3 + assert(r1 == 3); + printf("%d\n", r2); // expect: 8 + assert(r2 == 8); + printf("%d\n", r3); // expect: 9 + assert(r3 == 9); +} diff --git a/partition_min_num_deci_bin_num.py b/partition_min_num_deci_bin_num.py @@ -0,0 +1,21 @@ +# 1689. Partitioning Into Minimum Number Of Deci-Binary Numbers + +""" +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 possible deci-binary numbers needed so +that they sum up to 'n'. +""" + + +class Solution: + def minPartitions(self, n: str) -> int: + return int(max(n)) + + +if __name__ == "__main__": + obj = Solution() + print(obj.minPartitions(n="32")) + print(obj.minPartitions(n="82734")) + print(obj.minPartitions(n="27346209830709182346"))