why i am getting error in this questions

I am trying to solve this question i don’t know what i did wrong i am getting runtime error can any one help me in it

question: CodeChef: Practical coding for everyone

my solution #include
using namespace std;
int main()
{
int n=0;
long int a[100];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=n-1;i>=0;i–)
{
cout<<a[i]<<" ";
}
return 0;
}

The Constraints:

1\le N\le 10^5

and you’re using an array of size 100 :neutral_face:

1 Like

There are some bugs in your code:

1. You have used dash sign instead of minus at decrementing your i value in second loop.
2. Your header <iostream> is missing.
3. and array size bound, as mentioned above by @suman.

Here is your code after fixing above twos:

#include <iostream>
using namespace std;

int main()
{
    int n = 0;
    long long a[100];
    cin >> n;

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

    for (int i = n - 1; i >= 0; i--)
    {
        cout << a[i];
    }

    return 0;
}
1 Like

LOL., it still results in RTE.

2 Likes

What really?, But not in my VsCode.

1 Like

Here’s the link to the problem., submit the exact same code you pasted in the forum and see if it passes.

Not RTE, but WA I think because, this code bounds for only 100 size(where given constraints are 1≤N≤10^5), thats why it cause RTE. You can Check Here

1 Like

2 Likes

I got WA for the same!

After fixing size bound and putting white spaces after each element (output):

1 Like