⚡️ Tryprepforge
Backend Engineer Senior programming

Write a function to generate all permutations of a given string in such a way that each permutation is generated only once, even if there are duplicate characters in the string. ### Constraints: - The length of the string is between 1 and 9 inclusive. ### Examples: 1. Input: 'aabc' Output: ['aabc', 'aacb', 'abac', 'abca', 'acab', 'acba', 'baac', 'baca', 'bcaa', 'caba', 'cbaa'] 2. Input: 'xyz' Output: ['xyz', 'xzy', 'yxz', 'yzx', 'zxy', 'zyx']

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Backend Engineer Interview Prep

Link copied to clipboard