We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My first impulse here was a solution with a HashMap and a for loop, no deque.
I guess you can use a deque to maintain a rolling subarray as you read in values. That would save you some memory, especially if n is large and m is small. The tradeoff is an expensive call to deque.contains() every time you pop a number out of the deque.
Implementing a bfs (deque as a queue) or testing for palindromity (deque as a stack) would be a better simple practice problem for deques.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Dequeue
You are viewing a single comment's thread. Return to all comments →
My first impulse here was a solution with a HashMap and a for loop, no deque.
I guess you can use a deque to maintain a rolling subarray as you read in values. That would save you some memory, especially if n is large and m is small. The tradeoff is an expensive call to deque.contains() every time you pop a number out of the deque.
Implementing a bfs (deque as a queue) or testing for palindromity (deque as a stack) would be a better simple practice problem for deques.