Why am i getting WA (CARVANS)

My solution : CodeChef: Practical coding for everyone

question link : CodeChef: Practical coding for everyone

i am trying to check if previous value of car’s speed is greater than current value of speed and thus increment count variable .

so why am i getting wrong answer for this question .

I cannot access your code.
Maybe you are not updating the new speed of the car before comparing it with previous one.
Refer My solution: CodeChef: Practical coding for everyone

here is my code

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	// your code goes here
	short int T;
//    cin>>T;
    for (int i =0 ; i< T; i++){
        int N;
 //       cin>>N;
        int prev = 0;
        int cur;
        int count = 0;
        for (int j =0; j <N; j++){
//        cin>>cur;
        if (j == 0){
        prev = cur;
        else {
            if (cur<prev)                                          //checkpoint 1 ->  should there be an equal sign ?
        prev = cur;    
    } // Testcases ends over here
	return 0;

indent your code properly. I would advise you to always put braces around your if statements if it has multiple lines of code inside it.

Apart from that your code will still give TLE. Read the article below to resolve it.

1 Like