Problem Description
You need to maintain a queue that is initially empty. You will perform three types of operations on the queue -
1 X - Add the number x to the queue.
2 0 - Remove the least recently added number from the queue.
3 X - Consider the current numbers in the queue. Find the maximum size of a subset of numbers in the queue whose sum is X. If there is no such subset, return -1.
A subset is defined as a sequence that can be obtained by removing some (possibly all) elements present in the queue.
1 <= X <= 350
|A| <= 105
Input 1:
A : [ [1, 3] [1, 1] [1, 1] [2, 0] [3, 2] ]
Input 2:
A : [ [1, 1] [1, 2] [1, 2] [1, 3] [3, 4] [3, 5] ]
Output 1:
[2]
Output 2:
[2, 3]
Explanation 1:
After first 3 operations, queue becomes {3, 1, 1}. Then we pop the number 3. The queue is {1, 1}. Then we can form 2 by taking both the ones. So, we have a subset of 2 numbers.
Explanation 2:
After first 3 operations, queue becomes {1, 2, 2, 3}. Then 4 can be formed by 2 + 2 and 1 + 3. Max 2 numbers are in a subset. 5 can be formed by 1 + 2 + 2, 2 + 3 and 2 + 3. Max 3 numbers are in a subset.
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a question? Checkout Sample Codes for more details.