Does array works slower than int?

Why almost two similar codes with same logic are getting different outcomes?

The two solutions for the problem (ETUP) attached below look almost similar and their implementation is also same except for how the N integers are being taken and how the total count of even numbers is being computed.

In SOLUTION 1 the element is stored at the 0th index of array A, then it’s checked for being even or odd, the count variable is incremented if the integer is found even, the count variable is stored at the ith location of the array A.

In SOLUTION 2 the integer is stored in another variable named ele. Instead of having a counter variable, I am directly operating on the array’s i and i-1 location.

Problem: ETUP
Solution1 [TLE]: From line no. 12 to 19
Solution2 [AC] : From line no. 11 to 18

Stupidity at its peak. Why will it give TLE?

Coding practices matter a lot. What the hell is this?

#define int long long int

FYI, your array-based solution that resulted in TLE now runs faster than your AC solution.

Here’s a link to the submission.

1 Like

Thanks @suman_18733097 for pointing out the importance of good coding practices, I will always keep it in mind.

1 Like