Problem · Array
Custom-Sorted Array
Learn this problemProblem statement
In an array, elements at any two indices can be swapped in a single operation called a move. For example, if the array is arr = [17, 4, 8], swap arr[0] = 17 and arr[2] = 8 to get arr' = [8, 4, 17] in a single move. Determine the minimum number of moves required to sort an array such that all of the even elements are at the beginning of the array and all of the odd elements are at the end of the array.
Function
moves(arr: int[]) → int
Complete the function moves in the editor below.
moves has the following parameter(s):
int arr[N]: an array of positive integers
Returns
int: the minimum number of moves it takes to sort an array of integers with all
Examples
Example 1
arr = [6, 3, 4, 5]return = 1The following four arrays are valid custom-sorted arrays:
- a = [6, 4, 3, 5]
- a = [4, 6, 3, 5]
- a = [6, 4, 5, 3]
- a = [4, 6, 5, 3]
Constraints
🍉🍉More Snowflake problems
- Minimum N-ary Tree Depth DeletionsPHONE SCREEN · Seen Jul 2026
- Simulate a Queued Multi-Rule Rate LimiterPHONE SCREEN · Seen Jul 2026
- Minimum Clicks Between Wiki PagesOA · Seen Jul 2026
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerOA · Seen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringOA · Seen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026