values and an integer modulus. 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 leave the same remainder when divided by modulus.
Return the length of the longest such chain. Any two elements always make a valid chain.values=[3, 7, 1, 5, 9], modulus=4 → 3
The chain 1, 5, 9 works: the neighbouring sums 6 and 14 both leave remainder 2 when divided by 4.
values=[2, 5, 8, 11, 4], modulus=3 → 4
Every number but 4 leaves remainder 2 modulo 3, so all neighbouring sums in the chain 2, 5, 8, 11 leave remainder 1.
values=[6, 13], modulus=5 → 2
values=[3, 7, 1, 5, 9], modulus=4
3
Run checks the first 3 tests in your browser. Submit checks all 127 tests on the server, hidden ones included.