Can you explain me the question??
Importance of Time
You have to use 1 array and 1 queue, and you need to maintain 3 variables as total_time, job, executed_job all initialised to 0. Then you will check that
while (!q.empty())
{
if(q.front()==ar[executed_job])
{
total_time++;
executed_job++;
q.pop();
}
else
{
q.pop();
q.push();
total_time++;
}
Try using this logic
what i meant was an explanation of the test cases or the question as a whole not the logic behind solving it.
basically, the test case works in following manner : You have two arrays, ar1[ ] and ar2[ ]
You will take ar1[ ] and push its elements in queue, with initializing total time as 0. Then you will check if the front most element in the queue matches with the ar2[ ] first element, i.e
5 matches with 5 , thus total _time =1;
Then front element of queue becomes 4, and now 4 doesnt matches with 1, thus you will pop 4 from queue, and push it in end, total_time =2
Then front element of queue is 2, and 2 matches with 2 present in ar2[ ], thus you will pop 2 from queue and then total_time=3
Then front of queue becomes 3, and 3 doesnt match with 1 , and hence you pop it and push 3 in the end of queue, total_time=4
1 is next element of queue, which matches with the 1 present in ar2[ ] and hence total_time=5
Keep on doing this until all elements are popped from queue,
Final value after popping all elements from queue will be 7