There are two stacks(S1 and S2) of books. Each book in stack has a weight. You are given a net weight(W) of books that can be picked. You have to maximize the number of books that can be picked. Note that each time you can either pick from S1 or S2 only.
So answer:5(order:1,2 from s2,then all from s1)
I know this question can be done with a greedy approach by comparing top elements of both stacks, but can we solve it with the concept of trees?
Is there any other data structure that can be used to solve this problem?