FastPrepFirst Adjacent Same-Parity Pair

First Adjacent Same-Parity Pair

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

Return the zero-based left index of the first adjacent pair whose two values have the same parity. Return -1 when every adjacent pair has opposite parity.

Negative odd values are treated as odd.

Function

firstSameParityPair(values: int[]) → int

Examples

Example 1

values = [1,2,4,5]return = 1

The first same-parity pair begins at index one.

Example 2

values = [1,2,3,4]return = -1

Every adjacent pair has opposite parity.

Constraints

  • 0 <= values.length <= 100000
  • -1000000000 <= values[i] <= 1000000000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int firstSameParityPair(int[] values) {
    // Write your code here.
}
values[1,2,4,5]
expected1
Checking account…