Parity Placement Problem
Parity Placement Problem — ExecCode Medium DSA Practice
Solve the Parity Placement problem on ExecCode. Free online medium DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.
Problem description
You are given an array of N distinct integers. The array is properly arranged when every even index holds an even number and every odd index holds an odd number. You may swap any two elements. Return the minimum number of swaps needed, or -1 if it is impossible. Return the minimum swaps, or -1. You are given: a — a Return the minimum swaps, or -1. Copied from OA Lab Part 1.
Examples
Input {'a': [3, 2, 1, 4]}; Output 2. Input {'a': [1, 3, 5, 7]}; Output -1. Input {'a': [2, 3, 4, 1]}; Output 0
Constraints
Follow the statement. Use a 64-bit integer when values can overflow.
Practice Parity Placement free on ExecCode. Browse DSA problems, topic map, and placement guides.