We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
you build 3 new stacks with cumulative amounts. i.e. the first element is itself, the second contains the sum of the first and second, the third is the sum of the first,second and third and so on. This way you have the heights with each new addition. The top of each stack will have the height if all the cylinders are considered. The penultimate element of the stack has the height if the last element is not added. Let those stacks be h11 for vector h1, h22 for vector h2 and h33 for vector h3.
After this is done, you compare the heights of the three and pop the stack with the largest height.Repeat till all of them have the same height.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
you build 3 new stacks with cumulative amounts. i.e. the first element is itself, the second contains the sum of the first and second, the third is the sum of the first,second and third and so on. This way you have the heights with each new addition. The top of each stack will have the height if all the cylinders are considered. The penultimate element of the stack has the height if the last element is not added. Let those stacks be h11 for vector h1, h22 for vector h2 and h33 for vector h3.
After this is done, you compare the heights of the three and pop the stack with the largest height.Repeat till all of them have the same height.