Problem: Permutations of a String
Given a string STR
consisting of lowercase English letters, your task is to return all permutations of the given string in lexicographically increasing order.
Explanation:
A string A is lexicographically less than string B if either A is a prefix of B (and A ≠ B), or there exists such 'i' (1 ≤ i ≤ min(|A|, |B|)), that A[i] < B[i], and for any 'j' (1 ≤ j < i), A[j] = B[j]. Here |A| denotes the length of the string A.
Input:
The first line of input contains a single integer T
, representing the number of test cases or queries to be run. Then the T test cases follow.
The first and only line of each test case contains a string STR
consisting of lowercase English letters.
Output:
For every test case, the permutations of the given string are printed in lexicographically increasing order separated by space.
The output of each test case is printed on a separate line.
Example:
Input:
1
bca
Output:
abc acb bac bca cab cba
Constraints:
- 1 ≤ T ≤ 5
- 1 ≤ |STR| ≤ 9 where |STR| is the length of the string.
- Time Limit: 1 sec
Note:
The given string contains unique characters.

AnswerBot
4mo
Return all permutations of a given string in lexicographically increasing order.
Use backtracking to generate all permutations of the string.
Sort the permutations to get them in lexicographically incre...read more
Help your peers!
Add answer anonymously...
Ola Cabs Software Developer interview questions & answers
A Software Developer was asked 7mo agoQ. What is a closure?
A Software Developer was asked Q. Minimum Number Of Taps To Water Garden Problem Statement You are required to det...read more
A Software Developer was asked Q. Count Leaf Nodes in a Binary Tree Given a binary tree, your task is to count and...read more
Popular interview questions of Software Developer
A Software Developer was asked Q1. Minimum Number Of Taps To Water Garden Problem Statement You are required to det...read more
A Software Developer was asked Q2. Count Leaf Nodes in a Binary Tree Given a binary tree, your task is to count and...read more
A Software Developer was asked Q3. Diagonal Traversal of a Binary Tree Problem Statement Given a binary tree, your ...read more
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

