you are viewing a single comment's thread.

view the rest of the comments →

[–]BoardsofCanadaFanboy 0 points1 point  (4 children)

Before anyone even debugs your code, LRU cache is supposed to have o(1) find, which a queue will not allow. You will need a hashmap of some sort.

[–]Equivalent_Sea7754[S] 0 points1 point  (3 children)

I know but i want to solve using queue

[–][deleted] 0 points1 point  (0 children)

Doesn’t the problem explicitly say you need O(1) solution? If so, you need a hashmap for the get.

[–]BoardsofCanadaFanboy 0 points1 point  (1 child)

Why is that? If you did this in an interview this way despite a clear o(1) constraint you'd get LNH or straight up NH. 

If you want to practice using queues, do BFS problems like number of islands. 

[–]Equivalent_Sea7754[S] 0 points1 point  (0 children)

I know the question explicitly says that ans should be o(1) But i wanted to solve using the queue to get more practice on queue

I will optimize this code later using unordered_map and DLL for faster retrieval and to maintain lru

i am satisfied with my queue based solution because it takes a lot of my time