Sort a Binary Array
Updated
Problem statement
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
0or1.
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 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