Search
⌘K
Get Premium
Leetcode 3587. Minimum Adjacent Swaps to Alternate Parity
Given an array of distinct integers, find the minimum number of adjacent swaps to reorder it so parities alternate (even/odd/even/...), or return -1 if impossible. Key insight: feasibility requires the counts of evens and odds to differ by at most one, and the min swaps equals the minimal total displacement when matching current indices of one parity to target positions (try both starting-parity patterns).
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.