FastPrepCustom-Sorted Array
Problems/Custom-Sorted Array

Custom-Sorted Array

Snowflake logoSnowflake● EasyINTERNOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem 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):

  1. 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 = 1

The 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]

The most efficient sorting requires 1 move: swap the 4 and the 3.

Constraints

  • 🍉🍉

More Snowflake interview questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
  • Safest Shortest Path Through a GridOA · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
  • Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions
  • Get Maximum PairsAmazon · OA
  • Find Maximum GreatnessTwilio · OATwilio interview questions
  • Binge WatchingVanguard · OAVanguard interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
  • Minimum Last-Element RelocationsChubb · OAChubb interview questions
  • Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int moves(int[] arr) {
      // write your code here
    }

}
Checking account…