readings. Pick a chain from it (some elements in their original order, not necessarily adjacent) such that the sums of all neighbouring pairs in the chain have the same parity: either all even or all odd.
Return the length of the longest such chain. Any two elements always form a valid chain.readings=[5, 2, 8, 3, 6] → 4
The chain 5, 2, 3, 6 works: every neighbouring sum (7, 5, 9) is odd. Nothing longer fits.
readings=[7, 9, 11, 4] → 3
Take the three odd numbers: every neighbouring sum is even.
readings=[10, 3] → 2
readings=[5, 2, 8, 3, 6]
4
Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.