1689. Partitioning Into Minimum Number Of Deci-Binary Numbers

The idea of this solution is that the max digit in n will be the result. But you might be wondering why this works.

This works because the max digit can only be made by adding the max digit number of 1’s. If you don’t understand, look at the following image: The first image is an example, and the second example is for anyone who doesn’t understand the first example.

The Code:

func minPartitions(n string) int {
	max := '0'

	for _, i := range n {
		if i > max {
			max = i
		}
	}
	
	return int(max - '0')
}