FastPrepUnique String Permutations
Problems/Unique String Permutations

Unique String Permutations

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source requires all distinct permutations and explicitly notes duplicate characters, but it omits result ordering, an interface, and bounds. The judged output is lexicographically sorted, so the core task match is about 96%.

Given a lowercase string s, return every distinct permutation of its characters exactly once.

Return the permutations in ascending lexicographic order. Equal characters from different input positions must not create duplicate strings.

Function

uniquePermutations(s: String) → String[]

Examples

Example 1

s = "aab"return = ["aab","aba","baa"]

There are three distinct arrangements after duplicate swaps of the two a characters are removed.

Example 2

s = "xxyy"return = ["xxyy","xyxy","xyyx","yxxy","yxyx","yyxx"]

The four positions have six unique arrangements because each character appears twice.

Example 3

s = "z"return = ["z"]

A one-character string has one permutation.

Constraints

  • 1 <= s.length <= 8.
  • s contains only lowercase English letters.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public String[] uniquePermutations(String s) {
      // write your code here
    }
}
Checking account…