LeetCode 1689 | Partitioning Into Minimum Number Of Deci-Binary Numbers | Java | CodeByTushu
Description: π Welcome Back to CodeByTushu!
In todayβs video, we solve LeetCode 1689 β Partitioning Into Minimum Number Of Deci-Binary Numbers using Greedy and Digit Optimization in Java.
A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. Given a string n representing a positive decimal integer, our goal is to find the minimum number of positive deci-binary numbers needed to sum up to n. Because deci-binary numbers can only contribute 0 or 1 at each column position and carries cannot reduce the maximum digit demand across columns, the minimum count required is strictly bounded by the maximum digit present in n.
Our implementation performs a single linear scan across the string n to determine the maximum digit character. We also incorporate an early exit optimization: if the digit 9 is encountered at any point, the function terminates immediately and returns 9, since no decimal digit can ever exceed 9. This delivers an optimal O(n) runtime and O(1) auxiliary space complexity.
π₯ Problem Highlights
β Character digit parsing and running maximum tracking
β Column-wise additive lower bound analysis with zero carries
β Constructive proof showing sufficiency of max digit deci-binary numbers
β Early-exit optimization upon encountering the maximum possible digit 9
β In-place linear scan with zero heap memory allocation
β Optimal O(n) time and O(1) auxiliary space complexity
β±οΈ TIMESTAMPS
00:00 Intro & March 2026 Daily Challenge Kickoff
01:21 Problem Understanding & Deci-Binary Definition
02:45 Key Observation: Peak Column Value & Sufficiency
04:13 Greedy Maximum Digit Strategy (4 Steps)
05:26 Clean Java Solution Walkthrough Line by Line
06:34 Test Cases Walkthrough & Step-by-Step Simulation
07:57 Time Complexity Analysis (O(N) Time - 1 ms)
08:53 Space Complexity Analysis (O(1) Space)
09:36 Outro & Resources
π Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers
β Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/Solution.java
π Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.py
β‘ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.cpp
π JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.js
π LeetCode Source Code
π Admin type the link
π All LeetCode Solutions
π https://codebytushu.com/Leetcode/
π± Join CodeByTushu on WhatsApp
Get coding updates, LeetCode solutions, daily questions and more.
https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40
β€οΈ Donate
π https://codebytushu.com/Leetcode/donate.php
π₯ Perfect For
LeetCode Medium Problems
Java DSA Preparation
Greedy Algorithms
Digit Manipulation
String Traversal
Time Complexity Optimization
Coding Interview Preparation
Problem Solving
π Follow CodeByTushu
βΆοΈ YouTube: https://www.youtube.com/@codebytushu
πΈ Instagram: https://instagram.com/codebytushu/
πΌ LinkedIn: https://www.linkedin.com/company/codebytushu/
π Website: https://codebytushu.com
π GitHub: https://github.com/CodeByTushu
β€οΈ Donβt Forget To
π Like | π¬ Comment | π Subscribe
π¬ Question of the Day
Why is the minimum number of deci-binary numbers needed to sum up to n always equal to the maximum digit of n?
1οΈβ£ Because each deci-binary number contributes at most 1 at each column position
2οΈβ£ Because binary numbers cannot have carries
3οΈβ£ Because deci-binary numbers must always be powers of 10
4οΈβ£ Because the length of n determines the minimum number of summands
#LeetCode1689 #LeetCode #PartitioningIntoMinimumNumberOfDeciBinaryNumbers #Java #JavaDSA #Greedy #String #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu
π Comment the answer below! π₯Β Close description
In todayβs video, we solve LeetCode 1689 β Partitioning Into Minimum Number Of Deci-Binary Numbers using Greedy and Digit Optimization in Java.
A decimal number is called deci-binary if each of its digits is either 0 or 1 without any leading zeros. Given a string n representing a positive decimal integer, our goal is to find the minimum number of positive deci-binary numbers needed to sum up to n. Because deci-binary numbers can only contribute 0 or 1 at each column position and carries cannot reduce the maximum digit demand across columns, the minimum count required is strictly bounded by the maximum digit present in n.
Our implementation performs a single linear scan across the string n to determine the maximum digit character. We also incorporate an early exit optimization: if the digit 9 is encountered at any point, the function terminates immediately and returns 9, since no decimal digit can ever exceed 9. This delivers an optimal O(n) runtime and O(1) auxiliary space complexity.
π₯ Problem Highlights
β Character digit parsing and running maximum tracking
β Column-wise additive lower bound analysis with zero carries
β Constructive proof showing sufficiency of max digit deci-binary numbers
β Early-exit optimization upon encountering the maximum possible digit 9
β In-place linear scan with zero heap memory allocation
β Optimal O(n) time and O(1) auxiliary space complexity
β±οΈ TIMESTAMPS
00:00 Intro & March 2026 Daily Challenge Kickoff
01:21 Problem Understanding & Deci-Binary Definition
02:45 Key Observation: Peak Column Value & Sufficiency
04:13 Greedy Maximum Digit Strategy (4 Steps)
05:26 Clean Java Solution Walkthrough Line by Line
06:34 Test Cases Walkthrough & Step-by-Step Simulation
07:57 Time Complexity Analysis (O(N) Time - 1 ms)
08:53 Space Complexity Analysis (O(1) Space)
09:36 Outro & Resources
π Problem Folder & Detailed Documentation:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/tree/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers
β Java Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/Solution.java
π Python Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.py
β‘ C++ Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.cpp
π JavaScript Solution:
https://github.com/CodeByTushu/CodeByTushu-LeetCode-Solutions/blob/main/solutions/March/1-March/1689-Partitioning-Into-Minimum-Number-Of-Deci-Binary-Numbers/solution.js
π LeetCode Source Code
π Admin type the link
π All LeetCode Solutions
π https://codebytushu.com/Leetcode/
π± Join CodeByTushu on WhatsApp
Get coding updates, LeetCode solutions, daily questions and more.
https://whatsapp.com/channel/0029Vb8k5mCDeON2Xwlkxe40
β€οΈ Donate
π https://codebytushu.com/Leetcode/donate.php
π₯ Perfect For
LeetCode Medium Problems
Java DSA Preparation
Greedy Algorithms
Digit Manipulation
String Traversal
Time Complexity Optimization
Coding Interview Preparation
Problem Solving
π Follow CodeByTushu
βΆοΈ YouTube: https://www.youtube.com/@codebytushu
πΈ Instagram: https://instagram.com/codebytushu/
πΌ LinkedIn: https://www.linkedin.com/company/codebytushu/
π Website: https://codebytushu.com
π GitHub: https://github.com/CodeByTushu
β€οΈ Donβt Forget To
π Like | π¬ Comment | π Subscribe
π¬ Question of the Day
Why is the minimum number of deci-binary numbers needed to sum up to n always equal to the maximum digit of n?
1οΈβ£ Because each deci-binary number contributes at most 1 at each column position
2οΈβ£ Because binary numbers cannot have carries
3οΈβ£ Because deci-binary numbers must always be powers of 10
4οΈβ£ Because the length of n determines the minimum number of summands
#LeetCode1689 #LeetCode #PartitioningIntoMinimumNumberOfDeciBinaryNumbers #Java #JavaDSA #Greedy #String #DSA #CodingInterview #ProblemSolving #LeetCodeMedium #DailyLeetCode #JavaProgramming #CodeByTushu
π Comment the answer below! π₯Β Close description
