Why is my code showing wrong answer?

It seems to give perfect output for the test cases
Problem Link:

Submission Link:

You can’t only compare to the car directly ahead, you have to check more

What is the problem if I only compare with the car on the front?

I havent seen the question yet, but syntax error, in the function argument, you have used *sp, but you have passed by value, pass it by address

moreover, you are only comparing with the car that is in front of it, the speed of any car will only be maximum, if it is less than the slowest car in front of it, so take like a int min, and iterate through, whenever a car speed is less than that, then c++ and store that cars speed value in the int min