Notes on the Board
A notice board has room for k notes. Notes are pinned up one at a time, in the order of notes, where each number is what is written on a note. Whenever the board is already full, the note that has been up the longest is taken down to make room for the new one.
Return the notes on the board at the end, from the oldest to the newest.
Example 1
notes [4,7,1,9]
k 2
returns [1,9]
The board holds two notes. When 1 goes up, 4 comes down. When 9 goes up, 7 comes down.
Example 2
notes [4,7]
k 5
returns [4,7]
Two notes fit easily on a board for five, so nothing is taken down.
Example 3
notes []
k 3
returns []
No notes were pinned up.
Constraints
0 <= len(notes) <= 301 <= notes[i] <= 991 <= k <= 30
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- One-Bay Car WashBeginner
- Round the QueueBeginner
- Served in OrderBeginner
- Stack After CommandsBeginner
- Typing With UndoBeginner
- Card WarEasy
- Cups on the CounterEasy
- Depth If BalancedEasy