Why my code getting TLE


#1

My code is same as in solution but it is getting TLE .Can someone explain it?

#include<iostream>

using namespace std;

int main()  {
    int N;
    cin>>N;
    // YOUR CODE GOES HERE
    for(int i = 0; i < N; i++){
        if(i%2 == 0){
            continue;
        }
        cout<<i<<endl;
    }
    return 0;
}

#2

It’s not TLE it must be wrong answer as the loop must be <=N. Also you can try using “\n” rather than endl

#include<iostream>

using namespace std;

int main()  {
    int N;
    cin>>N;
    // YOUR CODE GOES HERE
    
    for(int i=0;i<=N;i++) {
        if(i%2==0)continue;
        cout<<i<<"\n";
    }
    return 0;
}

#3

In question it says that 0 <= i < N. But this code is giving TLE .Why?

#include
using namespace std;
int main() {
int N;
cin>>N;
// YOUR CODE GOES HERE
int i = 0;
while(i<N){
if(i%2==0){
continue;
}
cout<<i<<"\n";
i++;
}
return 0;
}


#4

The code is giving TLE because the value of i is not getting incremented. initial value of i is 0 and then it gets checked by if condition and immediately continues without incrementing the value of i.