1903. Design Most Recently Used Queue

Medium
Array
Linked List
Divide and Conquer
Design
Simulation
Doubly-Linked List

Description

Hints

Hint 1
You can store the data in an array and apply each fetch by moving the ith element to the end of the array (i.e, O(n) per operation).
Hint 2
A better way is to use the square root decomposition technique.
Hint 3
You can build chunks of size sqrt(n). For each fetch operation, You can search for the chunk which has the ith element and update it (i.e., O(sqrt(n)) per operation), and move this element to an empty chunk at the end.

Similar Questions

Statistics

Acceptance
77.7%
Submissions
32,348
Accepted
25,141