Sale
Summer Offer: $190/yr $99/yr
00 : 00 : 00 : 00
Get this deal
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

Trusted by 100+ professionals preparing for interviews

Trusted by 100+ professionals 50+ Company Question Banks 5+ Supported Languages

Practice More Questions Like This

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

Get Started Free
Link copied to clipboard