values and a list of queries ranges, where ranges[i] = [from, to]. For each query, decide whether parity alternates on the slice values[from..to] (inclusive): every two neighbouring numbers in it must have different parity. A one-number slice always qualifies.
Return a list of booleans where the i-th entry answers the i-th query.
There can be many queries, so rescanning each slice from scratch is too slow.values=[7, 2, 9, 4, 4, 1], ranges=[[0, 3], [2, 5], [4, 4]] → [True, False, True]
7, 2, 9, 4 alternate odd and even, so true. In 9, 4, 4, 1 the two even 4s are neighbours, so false. A one-element range always passes, so true.
values=[5, 11, 6], ranges=[[0, 2], [1, 2]] → [False, True]
5 and 11 are both odd, so the first range fails; in the second, 11 and 6 differ in parity.
values) ≤ 10⁵values[i] ≤ 10⁵ranges) ≤ 10⁵from ≤ to ≤ len(values) − 1values=[7, 2, 9, 4, 4, 1], ranges=[[0, 3], [2, 5], [4, 4]]
[True, False, True]
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.