Importance of time problem

Please suggest approach to this problem

@AbhishekAhlawat1102,

We have 2 cases associated with this question

Order in which all the processes are called.
Order in which all the processes should have been executed.

Sample test case
5
5 4 2 3 1
5 2 1 4 3

Executing a process takes 1 unit of time. Changing the position takes 1 unit of time.

for first itr:
both the index elements is same for first iteration i.e 5 match with 5
unit time is 1
so manage a variable as total_time and add the unit time into the total_time variable
now for second iteration
both the index elements is not same i.e 4 doesn’t match with 2
so we will remove 4 from that index and add to the last so the changing the position will take 1 unit of time
so total time will be total_time=total_time+1;
i.e total time will be 2

now the test case will be remaining
2 3 1 4
2 1 4 3
now in third iteration 2 match with 2 i.e total_time =total_time+1;
so total time will be 3
and remaining test case wil be
3 1 4
1 4 3
now in forth iteration 3 doesn’t match with 1 so we remove 3 from that index and add to the last and
again Changing the position takes 1 unit of time.
so total time here will be total_time=total_time+1;
i.e total time will be 4
and it will arrange like
1 4 3
1 4 3
now for the fifth iteration
1 match with 1
then total time will be 5;
for the sixth iteration
4 match with 4
then total time will be 6
for the seventh iteration
3 match with 3
then total time will be 7

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.