What to do in this question please tell me

i am not ableto understanding the question??>???

@kailash_01 hey , 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

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++;
}
:slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.