Importance of Time

need some hints as unable to find approach for it

Hey @Divya_321 try to formulate your logic by incorporating the data structure β€˜Queue’ in your approach.

@sdevwrat this is my codeLink:de.codingblocks.com/s/182206
I have according to me is working just fine but it’s giving me wrong ans please point out my mistake and correct it

Hey @Divya_321 your updation of time1 variable is not correct in the else part. It should be incremented by 1 for every pop operation and once again incremented when you come out of the loop. Take a look at the following snippet of code.
else{
while(calling.front()!=order[i]){
int temp = calling.front();
calling.pop();
calling.push(temp);
time1++;//once update here
}
time1 ++;//final update
calling.pop();
//cout<<order[i]<<" β€œ<<time1<<” "<<calling.front()<<endl;

    }
1 Like