All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : February 15, 2025
Last updated : February 15, 2025
Related Topics : Array, Hash Table, Stack, Design, Binary Indexed Tree, Ordered Set
Acceptance Rate : 77.66 %
This version does not implement the followup to reduce the O(n) complexity of
fetch()
. This will require following up to adjust in the future.
class MRUQueue:
def __init__(self, n: int):
self.q = list(range(1, n + 1))
def fetch(self, k: int) -> int:
self.q.append(self.q.pop(k - 1))
return self.q[-1]
# Your MRUQueue object will be instantiated and called as such:
# obj = MRUQueue(n)
# param_1 = obj.fetch(k)