Custom-Sorted Array

Problem Overview

  • Determine the minimum number of moves (each move swaps any two indices) to rearrange an array so all even numbers precede all odd numbers.
  • Input: arr[N] of positive integers; Output: int with the minimal number of moves.
  • Implement moves(arr) for this array partitioning problem.
  • Useful in data processing scenarios needing parity-based ordering.
  • Asked in Snowflake coding interviews; a common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: