FastPrepMove the Ones Before the Zeros
Problems/Move the Ones Before the Zeros

Move the Ones Before the Zeros

Adobe logoAdobe● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You move every 1 in an array of 0s and 1s to the front and every 0 to the back. An Adobe software quality engineer (automation) report from Calcutta (March 2024) lists it as the first of two coding questions in the first of three coding rounds. It is stated only as one sample array and the array it should turn into. It says nothing about working in place, speed or limits.

We chose these rules. The function returns the rearranged array, and changing the input is allowed. Arrays hold 1 to 5000 values. We wrote new examples. The editorial also shows a one-pass, in-place version.

Our version is about 90% the same as the reported question.

Given an array nums that contains only 0s and 1s, rearrange it so that every 1 comes before every 0, and return the result.

You may change nums itself and return it, or return a new array.

Function

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

Examples

Example 1

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

There are two 1s and two 0s, so the result is the two 1s followed by the two 0s.

Example 2

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

There are no 1s, so the array stays all 0s.

Example 3

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

Four 1s and four 0s: [1,1,1,1,0,0,0,0].

Constraints

  • 1 <= nums.length <= 5000
  • Each nums[i] is 0 or 1

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
  • Remove Duplicates from Sorted ArrayNykaa · PHONE SCREENNykaa interview questions
  • Minimum Index Distance Between Person and CakeSnowflake · OA · PHONE SCREENSnowflake interview questions
  • Squares of a Sorted ArrayInstacart · PHONE SCREENInstacart interview questions
  • Closest Vehicle and Charger in a LineSpotify · PHONE SCREEN
  • Correct an In-Place Array ReversalDuolingo · PHONE SCREENDuolingo interview questions
  • Remove Duplicates From Sorted Array In PlaceKotak Mahindra Bank · PHONE SCREEN · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Merge Two Sorted ArraysCapgemini · PHONE SCREENCapgemini interview questions
  • Maximize Distance to the Closest Occupied SeatAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Remove Duplicates From Sorted Array In PlaceGet My Parking · PHONE SCREEN

Interview reports that mention this question

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)

Adobe interview experiences

  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
  • Adobe Product Intern Interviews: 15 Experiences (Part 3 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
class Solution {
    public int[] onesBeforeZeros(int[] nums) {
        // Write your code here.
    }
}
Checking account…