FastPrepGenerate All Permutations of a Number
Problems/Generate All Permutations of a Number

Generate All Permutations of a Number

Fleetx logoFleetx● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Fleetx SDE 2 onsite interview, where it was one of two coding tasks in the first round. The task was to list every way to reorder the digits of a number.

The report gives no input format, limits or examples. Here the digits come as an array of 1 to 8 digits, and a digit can repeat. Each different ordering is returned once, orderings that start with 0 count, and the list comes back in lexicographic order.

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

Given an integer array nums that holds the digits of a number, return every distinct permutation of those digits in lexicographic order.

A permutation uses every element of nums exactly once. The same digit can appear more than once in nums, and permutations that read the same are returned only once. A permutation may start with 0.

Lexicographic order compares two permutations from left to right: at the first position where they differ, the one with the smaller digit comes first.

Function

permuteUnique(nums: int[]) → List<List<Integer>>

Examples

Example 1

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

The two 2s are the same digit, so swapping them gives nothing new. Of the 6 ways to order three items, only 3 are different, and they are listed from smallest to largest.

Example 2

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

All three digits are different, so all 3 * 2 * 1 = 6 orderings appear. The ones that start with 0, such as [0,1,3], count too.

Example 3

nums = [9,9]return = [[9,9]]

Both orderings of the two 9s read [9,9], so it is returned once.

Constraints

  • 1 <= nums.length <= 8
  • 0 <= nums[i] <= 9

More Fleetx Onsite Interview questions

  • Sustained Overspeed AlertsONSITE INTERVIEW · Seen Nov 2026
  • Number of IslandsONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Bounded Combination Sum with Signed CandidatesConfluent · ONSITE INTERVIEWConfluent interview questions
  • Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions
  • Subsets IIBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Generate Circular Student ArrangementsAmazon · ONSITE INTERVIEW
  • Enumerate Compatible Meeting SubsetsExpedia · ONSITE INTERVIEWExpedia interview questions
  • Partition into Equal-Sum GroupsPalo Alto Networks · ONSITE INTERVIEWPalo Alto Networks interview questions
  • PermutationsEPAM · PHONE SCREENEPAM interview questions
  • Combination Sum with Single-Use ValuesPinterest · PHONE SCREENPinterest interview questions
  • Combination Sum with Unlimited ReuseNVIDIA · PHONE SCREENNVIDIA interview questions
  • Sort by Checking PermutationsMercor · PHONE SCREENMercor interview questions
See Fleetx hiring insights
Saved
class Solution {
    public List<List<Integer>> permuteUnique(int[] nums) {
        // Write your code here.
    }
}
Checking account…