We are given $n$, with $3 \leq n \leq 100$, followed by a list of $n$ numbers. One of them differs in parity, and we need to find the $1$-based index of the offending number. The problem is simple, so the only goal here is to implement it quickly.
In C++, I'm using find_if
to return an iterator to the offending position, then getting the
0-based index by doing what is essential pointer arithmetic, subtracting
the A.begin()
iterator from the result. Of course, a plus
one correction is needed since our problem asks for a 1-based index.
Both language implementations are similar in code length, though the Python one is maybe faster to write (and the input is small).