cards cards numbered 1 to cards. At first they are in order, [1, 2, ..., cards], with card 1 on top.
A librarian handles the requests in requests one by one. For a request v they find card v, note its position in the stack (the top card is position 0), pull it out and put it back on top. The other cards keep their relative order.
Return the noted positions, one per request, in the order the requests were handled.requests=[2, 2, 4, 1], cards=4 → [1, 0, 3, 2]
The stack is [1, 2, 3, 4]. Card 2 sits at position 1, leaving [2, 1, 3, 4]; now 2 is on top, so position 0. Card 4 is at position 3, giving [4, 2, 1, 3], and finally card 1 is at position 2.
requests=[3], cards=3 → [2]
A single request: card 3 is at the very bottom of [1, 2, 3], position 2.
requests=[1, 1, 1], cards=2 → [0, 0, 0]
Card 1 starts on top and goes back on top after every request, so every answer is 0.
cards ≤ 1000requests.length ≤ 1000requests[i] ≤ cardsrequests=[2, 2, 4, 1], cards=4
[1, 0, 3, 2]
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.