Another Approach
in this lecture deepak sir saying that push is in o(1) and pop is expensive.I understand that…He added that we can make pop() in O(1) and push function expensive…can you tell me how ??
Hi Gaurav, in the given video, sir made push in O(1) by normal insertion at front of queue. and pop by pushing n-1 elements in second queue. You can make pop in O(1) by just reversing the functions of insertion and pushing of n-1 elements amongst both the queues.
Hey Gaurav,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.
Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.