Question 11
Our approach will be to building a DP table of the same length as the array of disks. Let denote the disk in the input array.
The value of will be the height of the tallest tower that can be created with the bottom. We initialize the value of the height of .
Consider the following approach. We process the DP array in increasing order of indices (i.e, to ). We look at all disks where and can be placed on top of . If can be placed on top of , then is updated to be the maximum of and , where is the height of the disk . What can you say about this approach?
This approach is correct.
This approach is incorrect, because we might miss some disks that can be placed on top of di,as the given array may not be sorted by height.
This approach is incorrect because the values we are looking up may not be computed correctly when we need them.