What is wrong with the code

Kunal, 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())
{
job=q.front();
if(job==ar[executed_job])
{
total_time++;
executed_job++;
q.pop();
}
else
{
q.pop();
q.push();
total_time++;
}

Try using this logic