FastPrepNext Permutation
Problems/Next Permutation

Next Permutation

Meta logoMeta● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta phone screen. The report names the next largest permutation. The well-known next-permutation task sets the order, the wrap-around and the in-place rule. Here, the function returns the changed array. Our version is about 95% the same as the reported question.

Rearrange nums into the next lexicographically greater permutation of its values. A permutation uses every value exactly as often as it appears in the input.

Compare two arrays at their first differing position; the array with the smaller value there comes first. If the input is already the greatest permutation, rearrange it into increasing order instead.

Modify the array in place using constant auxiliary space. For this exercise, assume the function returns the modified array so its result exposes the rearrangement.

Function

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

Examples

Example 1

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

The next ordering after [1,2,3] is [1,3,2].

Example 2

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

The greatest permutation wraps around to [1,2,3].

Example 3

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

Repeated values remain repeated; the next distinct ordering is [1,5,1].

Example 4

nums = [2,4,3,1]return = [3,1,2,4]

Increase the first value from 2 to 3, then minimize the suffix to obtain [3,1,2,4].

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 100

More Meta Phone Screen questions

  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
  • First Element Greater Than KPHONE SCREEN · Seen Nov 2026
  • Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
  • Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
  • Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Values Exclusive to the Current UserPHONE SCREEN · Seen Sep 2026
  • First Bad Version in a Monotone ArrayPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

  • Merge Sorted Squares of Two ArraysWhatNot · PHONE SCREENWhatNot interview questions
  • Interval List IntersectionsGrammarly · PHONE SCREEN
  • Subarray Product Less Than KApple · PHONE SCREENApple interview questions
  • 3SumAmazon · PHONE SCREEN
  • Subarray Product Less Than KAngel One · PHONE SCREEN
  • Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions
  • Sort Ones, Twos, and Threes In PlaceAgoda · PHONE SCREEN · ONSITE INTERVIEWAgoda interview questions
  • Candy Crush Grid Matching and GravityRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta Software Engineer Onsite Questions: 3 Experiences
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public int[] nextPermutation(int[] nums) {
        // Write your code here.
    }
}
Checking account…