0% completed
Trying to understand advantage
Sandeep Gattani
Nov 30, 2023
What is the benefit of using Queue for this purpose and use additional space - instead of simply having reference of the 2 queues and switching between them?
3
0
Comments
Syed Ahmed 2 years ago
Can you explain what you mean changing the references ?
I think they want to check how we will use Queue & know how it operates. There are definitely others ways of achieving it -- likely using toggle flag in next method to return from each list while maintaining a c...
ozbek.su 5 months ago
I agree with Sandeep here.
Let's say V1 is N size, V2 is M size and non-empty lists:
the space complexity with 2 queue solution is O(N+M) since we clone the list into the queues.
the time complexity is the same since you need a while loop with hasNext to dequeue ...
n.place 2 months ago
100%. The solution that they provide is just using a single queue for the sake of using a single queue, when alternating between 2 would be better (not just in efficiency but in readability!). In their solution, the enqueue operation involves allocating a new array [arr...
On this page