{"id":"f3b60564-8c0e-48f4-b18c-6d721db5d4bb","name":"Permutations - Words - 2","description":" 1. You are given a word (may have one character repeat more than once).\r\n2. You are required to generate and print all arrangements of these characters. \r\n\r\nNote -> Use the code snippet and follow the algorithm discussed in question video. The judge can't \r\n force you but the intention is to teach a concept. Play in spirit of the question.\r\n ","inputFormat":"Input is managed for you","outputFormat":"Check the sample ouput and question video. ","constraints":"0 &lt; str.length() &lt;= 4","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void generateWords(int cc, String str, Character[] spots, \r\n HashMap<Character, Integer> lastOccurence) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String str = br.readLine();\r\n\r\n Character[] spots = new Character[str.length()];\r\n HashMap<Character, Integer> lastOccurence = new HashMap<>();\r\n for(char ch: str.toCharArray()){\r\n lastOccurence.put(ch, -1);\r\n }\r\n\r\n generateWords(0, str, spots, lastOccurence);\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabb","sampleOutput":"aabb\r\nabab\r\nabba\r\nbaab\r\nbaba\r\nbbaa","questionVideo":"https://www.youtube.com/embed/D7kSjpIVQFA?end=411","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"c0b0d771-ec20-4be7-bd1f-6c65c8febef3","name":"Permutations - Words - 2","slug":"permutations-words-2","type":1}],"next":{"id":"9c309b80-dfcd-4aee-92c0-3082fd38e26f","name":"Permutations-words-2 MCQ","type":0,"slug":"permutations-words-2-mcq"},"prev":{"id":"6c96aa88-0cb8-4e1e-8744-e679b5651e68","name":"Permutations-words-1 MCQ","type":0,"slug":"permutations-words-1-mcq"}}}

Permutations - Words - 2

1. You are given a word (may have one character repeat more than once). 2. You are required to generate and print all arrangements of these characters. Note -> Use the code snippet and follow the algorithm discussed in question video. The judge can't force you but the intention is to teach a concept. Play in spirit of the question.

{"id":"f3b60564-8c0e-48f4-b18c-6d721db5d4bb","name":"Permutations - Words - 2","description":" 1. You are given a word (may have one character repeat more than once).\r\n2. You are required to generate and print all arrangements of these characters. \r\n\r\nNote -> Use the code snippet and follow the algorithm discussed in question video. The judge can't \r\n force you but the intention is to teach a concept. Play in spirit of the question.\r\n ","inputFormat":"Input is managed for you","outputFormat":"Check the sample ouput and question video. ","constraints":"0 &lt; str.length() &lt;= 4","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n public static void generateWords(int cc, String str, Character[] spots, \r\n HashMap<Character, Integer> lastOccurence) {\r\n // write your code here\r\n }\r\n\r\n public static void main(String[] args) throws Exception {\r\n BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r\n String str = br.readLine();\r\n\r\n Character[] spots = new Character[str.length()];\r\n HashMap<Character, Integer> lastOccurence = new HashMap<>();\r\n for(char ch: str.toCharArray()){\r\n lastOccurence.put(ch, -1);\r\n }\r\n\r\n generateWords(0, str, spots, lastOccurence);\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabb","sampleOutput":"aabb\r\nabab\r\nabba\r\nbaab\r\nbaba\r\nbbaa","questionVideo":"https://www.youtube.com/embed/D7kSjpIVQFA?end=411","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"082986ae-d618-4a59-9ab3-6d79056679a4","name":"Recursion and Backtracking For Intermediate","slug":"recursion-and-backtracking-for-intermediate-330","type":0},{"id":"c0b0d771-ec20-4be7-bd1f-6c65c8febef3","name":"Permutations - Words - 2","slug":"permutations-words-2","type":1}],"next":{"id":"9c309b80-dfcd-4aee-92c0-3082fd38e26f","name":"Permutations-words-2 MCQ","type":0,"slug":"permutations-words-2-mcq"},"prev":{"id":"6c96aa88-0cb8-4e1e-8744-e679b5651e68","name":"Permutations-words-1 MCQ","type":0,"slug":"permutations-words-1-mcq"}}}
plane

Editor


Loading...

Permutations - Words - 2

easy

1. You are given a word (may have one character repeat more than once). 2. You are required to generate and print all arrangements of these characters. Note -> Use the code snippet and follow the algorithm discussed in question video. The judge can't force you but the intention is to teach a concept. Play in spirit of the question.

Constraints

0 < str.length() <= 4

Format

Input

Input is managed for you

Output

Check the sample ouput and question video.

Example

Sample Input

aabb

Sample Output

aabb abab abba baab baba bbaa

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode