In this question I came up with a O(n^2) solution but the constraint is n<10^6 . How my solution got accepted?
Is there any O(n) solution please help me
Question :Importance of time(challenges of stack and queue)
hello @sandipan.bublu
- The Idea is to Store the Calling order in Queue and the ideal order in an Array.
- Then compare front element of the queue with the ideal order.
- If it matches then increment the time and remove the element.
- Else, Dequeue the element and enqueue it again.
- The loop will run till the queue is consumed totally.
code->https://ide.codingblocks.com/s/247225
complexity is nearly O(n^2)
there is no O(N) solution