FastPrepSort a Binary Array
Problems/Sort a Binary Array

Sort a Binary Array

AMD logoAMD● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an AMD full-time onsite interview. The report gives the task of sorting a binary array. We chose the shape of what is returned, whether you change the input, and the limits, so the answer is always the same. Our version is about 96% the same as the reported question.

Given an integer array containing only 0 and 1, return the values in non-decreasing order.

Preserve the input array and return a newly arranged array.

Function

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

Examples

Example 1

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

All zeros precede all ones.

Example 2

nums = [1,1]return = [1,1]

An already sorted array is unchanged.

Constraints

  • 0 <= nums.length <= 100000.
  • Every value is 0 or 1.

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

More AMD Onsite Interview questions

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Predict Runtime Method DispatchONSITE INTERVIEW · Seen Oct 2026
  • K Largest Elements with QuickselectONSITE INTERVIEW · Seen Sep 2026
  • Climbing StairsONSITE INTERVIEW · Seen Sep 2026
  • First-Fit Arena AllocatorPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Coins for an AmountONSITE INTERVIEW · Seen Sep 2026
  • Growing Circular QueueONSITE INTERVIEW · Seen Feb 2026
  • Parse a Binary Firmware HeaderONSITE INTERVIEW · Seen Feb 2026
  • Matrix Multiplication and Parallel PartitionsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • Valid Times on a Digital ClockToptal · OA · ONSITE INTERVIEW
  • Count Triplets With Sum at Most TargetGoogle · ONSITE INTERVIEWGoogle interview questions
  • Reduce Array Size to At Most HalfMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Best Poker Category with a JokerScale AI · PHONE SCREEN · ONSITE INTERVIEWScale AI interview questions
  • Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
  • Find All Zip Rummy MeldsZip · PHONE SCREEN · ONSITE INTERVIEWZip interview questions
  • Coin Change IIApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
  • Partition into Equal-Sum GroupsPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • Inventory Outfit CombinationsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions

Interview reports that mention this question

  • AMD Experienced SWE Interviews: 6 Experiences (Part 1 of 3)

AMD interview experiences

  • AMD GPU and Verification Interviews: 3 Experiences (Part 3 of 3)
  • AMD SDE2 and AI Engineer Interviews: 7 Experiences (Part 2 of 3)
  • AMD New Grad Role Interviews: 3 Experiences (Part 2 of 2)
  • AMD ML and GPU Intern Interviews: 7 Experiences (Part 2 of 2)
  • AMD Interviews by Role, Level Not Reported: 9 Experiences
All AMD interview questionsSee AMD hiring insights
Saved
class Solution {
    public int[] sortBinaryArray(int[] nums) {
        // Write your code here.
    }
}
Checking account…