FastPrepSort Colors
Problems/Sort Colors

Sort Colors

Visa logoVisa● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names a well-known task. We chose the function signature, a fixed order for the output, and the input limits. Our version is about 98% the same as the reported question.

You are given an integer array nums containing only 0, 1, and 2. Rearrange the array in place so that equal values are adjacent and the values appear in the order 0, 1, then 2.

Do not call a library sorting routine. Return the same array after rearranging it so the result can be evaluated.

Function

sortColors(nums: int[]) → int[]

Examples

Example 1

nums = [2,0,2,1,1,0]return = [0,0,1,1,2,2]

The two zeros come first, followed by the two ones and the two twos.

Example 2

nums = [2,0,1]return = [0,1,2]

Each color occurs once.

Constraints

  • 1 <= nums.length <= 100000
  • nums[i] is 0, 1, or 2.
  • The rearrangement must use constant auxiliary space.

Source note: Author-written prompt excerpt retained for source fidelity.

More Visa interview questions

  • House RobberPHONE SCREEN · Seen Nov 2026
  • House Robber IIIPHONE SCREEN · Seen Nov 2026
  • Find the Intersection Node of Two Linked ListsPHONE SCREEN · Seen Sep 2026
  • Count Prime Values in SubtreesOA · Seen Nov 2026
  • Lock CodeOA · Seen Nov 2026
  • Minimum-Sum Tree Fill with Unit StepsOA · Seen Nov 2026
  • Longest Non-Decreasing Substring After Pair SwapsOA · Seen Oct 2026
  • Count Attack Vectors by Divisor RangeOA · Seen Oct 2026
  • Minimum Operations to Reduce a Transaction LedgerOA · Seen Oct 2026
  • Count Valid Space-Delimited WordsOA · Seen Oct 2026

Similar questions at other companies

  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • 3SumAmazon · PHONE SCREEN
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
  • Meeting Rooms IIUber · PHONE SCREENUber interview questions
  • Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
  • Count Triplets Within a Value RangeIBM · PHONE SCREENIBM interview questions
  • 3SumMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Meeting Rooms IIWalmart · PHONE SCREENWalmart interview questions
  • 3SumApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
All Visa interview questionsSee Visa hiring insights
Saved
class Solution {
    public int[] sortColors(int[] nums) {
      // write your code here
    }

}
Checking account…