Why I am getting different output on HackerRank than the output of my IDE?


I am trying to solve a problem named "Jumping on the Clouds" on HackerRank.

I have written a code primarily and it gives the right output as my expectations. But when I am submitting the code on HackerRank it gives different output with the same input. How it is possible!

I tried to compile in different IDE and text editors like CodeBlocks, VSCode, and an online compiler(Ideone) and they give the correct output but HackerRank is showing a different output.

My code (C++):

#include <iostream>

using namespace std;

int main() {
  int n, count = 0;
  cin >> n;

  int arr[n];
  for(int i = 0; i < n; i++) {
    cin >> arr[i];

  for(int i = 0; i < n; i++) {
    if(arr[i + 2] == 0) {
      i = i + 1;
    } else if(arr[i + 1] == 0) {
    } else {

  cout << count << endl;

  return 0;

Output on VSCode:

enter image description here

Output on Ideone:

enter image description here

Output on HackerRank:

enter image description here

enter image description here

Problem link: Jumping on the Clouds

Where is the problem and how to solve it?

Source: Windows Questions C++