parv2809's blog

By parv2809, history, 4 years ago, In English

We need to maintain a queue that is initially empty. We need to perform three types of operations on the queue:

- 1 X - add number X to the queue
- 2 0 - remove the least recently added number from the queue (basically from the front of the queue)
- 3 X - consider the current numbers in the queue and find the max 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.
input: a 2d array A containing the sequence of operations done on the queue.

~~~~~ Constraints-

1<=X<=350

|A|<=10^5

  • Vote: I like it
  • +16
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by parv2809 (previous revision, new revision, compare).