Diving Board
16.11 Diving Board: You are building a diving board by placing a bunch of planks of wood end-to-end. There are two types of planks, one of length shorter and one of length longer. You must use exactly K planks of wood. Write a method to generate all possible lengths for the diving board.
Not the most efficient, but we can build a B-tree that expands out to represent the possible combinations given k planks (building k levels in the process.
Each node will represent the accumulative length until we get to the leafs. Our final result will be the values of our leafs in the tree.
The reason this isn't entirely efficient is because we will obtain so overlap in the sum of the values (2+3) = (3+2), but our tree distinct them as different.
The larger the k, the more overlaps.
Optimized: With only two possibilities and k levels. The unique combinations made are simple:
Ex.
len1 = 3, len2 = 4, k = 4
Produces unique sums that are reflected by: its key combination:
2222 = 8
2223 = 9
2233 = 10
2333 = 11
3333 = 12
Last updated