{"id":"4e5e7d2a-5890-4489-b075-9cf62fd03141","name":"Permutations - Words - 1","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.","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 cs, int ts, HashMap<Character, Integer> fmap, String asf) {\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 HashMap<Character, Integer> fmap = new HashMap<>();\r\n for(char ch: str.toCharArray()){\r\n if(fmap.containsKey(ch)){\r\n fmap.put(ch, fmap.get(ch) + 1);\r\n } else {\r\n fmap.put(ch, 1);\r\n }\r\n }\r\n\r\n generateWords(1, str.length(), fmap, \"\");\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/4-Makzrj5qM?end=921","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":"2e73cf2a-9b48-433c-9357-4192f96ca8cb","name":"Permutations - Words - 1","slug":"permutations-words-1","type":1}],"next":{"id":"6c96aa88-0cb8-4e1e-8744-e679b5651e68","name":"Permutations-words-1 MCQ","type":0,"slug":"permutations-words-1-mcq"},"prev":{"id":"dc4173ce-df9e-4001-bddd-c8d45da467a8","name":"Combinations -2 MCQ","type":0,"slug":"combinations-2-mcq"}}}

Permutations - Words - 1

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":"4e5e7d2a-5890-4489-b075-9cf62fd03141","name":"Permutations - Words - 1","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.","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 cs, int ts, HashMap<Character, Integer> fmap, String asf) {\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 HashMap<Character, Integer> fmap = new HashMap<>();\r\n for(char ch: str.toCharArray()){\r\n if(fmap.containsKey(ch)){\r\n fmap.put(ch, fmap.get(ch) + 1);\r\n } else {\r\n fmap.put(ch, 1);\r\n }\r\n }\r\n\r\n generateWords(1, str.length(), fmap, \"\");\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/4-Makzrj5qM?end=921","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":"2e73cf2a-9b48-433c-9357-4192f96ca8cb","name":"Permutations - Words - 1","slug":"permutations-words-1","type":1}],"next":{"id":"6c96aa88-0cb8-4e1e-8744-e679b5651e68","name":"Permutations-words-1 MCQ","type":0,"slug":"permutations-words-1-mcq"},"prev":{"id":"dc4173ce-df9e-4001-bddd-c8d45da467a8","name":"Combinations -2 MCQ","type":0,"slug":"combinations-2-mcq"}}}
plane

Editor


Loading...

Permutations - Words - 1

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