Incomprehensible Question

Please explain the input and output. How did the answer come from the input? I am not understanding anything in this.

Hi @rishabhsetiya7,
In this question there is one ideal order in which the process has to be executed and one is the order in which the process are called.Now in the example ideal order is 5 4 2 3 1 and calling order is 5 2 1 4 3 so here 5 is at the same position in both,so time is incremented by one and remove next ideal order is 4 2 3 1 and calling order is 2 1 4 3 now at the front two elements are different so push 4 at the last in the ideal order then the order will become 2 3 1 4 and calling order is 2 1 4 3 so 2 becomes same then time is incremented but this time 2 times as one for pushing back the process and one simply for executing.Like this when you will do till the calling array becomes empty.

Thank you so much ma’am.