Importance of time


I am getting tle error .please correct my code

@Megha2468 your code take o(n*n) time which will lead to tle as constraints are large . try to think of o(n) approach

how can i reduce complexity and at the same time use arrays.should I use two queue in place of array.

You can do this using 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
Do you want me to share the code too @Megha2468?

ok the problem is solved.Thanks

@Megha2468 you are welcome just mark the doubt resolved then :smiley: