Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.22 KB

_1756. Design Most Recently Used Queue.md

File metadata and controls

49 lines (33 loc) · 1.22 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


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 %


Version 1

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.


Solutions

Python

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)