Skip to content

Latest commit

 

History

History
38 lines (30 loc) · 1.66 KB

File metadata and controls

38 lines (30 loc) · 1.66 KB

< Previous                  Next >

Related Topics

[Stack] [Design] [Binary Indexed Tree] [Array] [Hash Table] [Ordered Set]

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.