Skip to content

Commit a00eda4

Browse files
committed
Have implemented the program to find the minimum number of positive deci-binary numbers needed so that they sum up to n.
1 parent 0411745 commit a00eda4

File tree

2 files changed

+78
-31
lines changed

2 files changed

+78
-31
lines changed

.idea/workspace.xml

Lines changed: 32 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Partitioning Into Minimum Number Of Deci-Binary Numbers
3+
Link: https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/description/
4+
5+
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.
6+
7+
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.
8+
9+
Example 1:
10+
Input: n = "32"
11+
Output: 3
12+
Explanation: 10 + 11 + 11 = 32
13+
14+
Example 2:
15+
Input: n = "82734"
16+
Output: 8
17+
18+
Example 3:
19+
Input: n = "27346209830709182346"
20+
Output: 9
21+
22+
Constraints:
23+
1 <= n.length <= 105
24+
n consists of only digits.
25+
n does not contain any leading zeros and represents a positive integer.
26+
*/
27+
28+
package com.raj;
29+
30+
public class PartitioningIntoMinimumNumberOfDeciBinaryNumbers {
31+
public static void main(String[] args) {
32+
// Initialization.
33+
String n = "32";
34+
int ans = 0;
35+
36+
// Logic.
37+
for (char a : n.toCharArray()) {
38+
if (ans < a - '0') {
39+
ans = a - '0';
40+
}
41+
}
42+
43+
// Display the result.
44+
System.out.println(ans + " minimum number of positive deci-binary numbers needed so that they sum up to " + n + ".");
45+
}
46+
}

0 commit comments

Comments
 (0)