{"id":"3f47d8ab-da32-42bc-a8d4-229d8e76b60f","name":"Words - K Selection - 3","description":"1. You are given a word (may have one character repeat more than once).\r\n2. You are given an integer k.\r\n2. You are required to generate and print all ways you can select k characters out of the word.\r\n\r\nNote -> 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.\r\n","inputFormat":"Input is managed for you","outputFormat":"Check the sample ouput and question video. ","constraints":"0 &lt; str.length() &lt; 15\r\n0 &lt; k &lt;= str.length()","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\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 int k = Integer.parseInt(br.readLine());\r\n\r\n HashMap<Character, Integer> unique = new HashMap<>();\r\n String ustr = \"\";\r\n for (char ch : str.toCharArray()) {\r\n if (unique.containsKey(ch) == false) {\r\n unique.put(ch, 1);\r\n ustr += ch;\r\n } else {\r\n unique.put(ch, unique.get(ch) + 1);\r\n }\r\n }\r\n\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"aab\r\naac\r\naad\r\naae\r\nabb\r\nabc\r\nabd\r\nabe\r\nacc\r\nacd\r\nace\r\nadd\r\nade\r\nbbb\r\nbbc\r\nbbd\r\nbbe\r\nbcc\r\nbcd\r\nbce\r\nbdd\r\nbde\r\nccd\r\ncce\r\ncdd\r\ncde\r\ndde","questionVideo":"","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":"82434199-fab0-48f0-aa58-3491e914eedb","name":"Words - K Selection - 3","slug":"words-k-selection-3","type":1}],"next":{"id":"481c8428-2b4b-4051-afa8-09ab94721b88","name":"Words - K Selection - 3 MCQ","type":0,"slug":"words-k-selection-3-mcq"},"prev":{"id":"64f942e5-1a07-4063-a911-e0d73cb26534","name":"Coin Change - Combinations - 2 MCQ","type":0,"slug":"coin-change-combinations-2-mcq"}}}

Words - K Selection - 3

1. You are given a word (may have one character repeat more than once). 2. You are given an integer k. 2. You are required to generate and print all ways you can select k characters out of the word. 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":"3f47d8ab-da32-42bc-a8d4-229d8e76b60f","name":"Words - K Selection - 3","description":"1. You are given a word (may have one character repeat more than once).\r\n2. You are given an integer k.\r\n2. You are required to generate and print all ways you can select k characters out of the word.\r\n\r\nNote -> 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.\r\n","inputFormat":"Input is managed for you","outputFormat":"Check the sample ouput and question video. ","constraints":"0 &lt; str.length() &lt; 15\r\n0 &lt; k &lt;= str.length()","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\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 int k = Integer.parseInt(br.readLine());\r\n\r\n HashMap<Character, Integer> unique = new HashMap<>();\r\n String ustr = \"\";\r\n for (char ch : str.toCharArray()) {\r\n if (unique.containsKey(ch) == false) {\r\n unique.put(ch, 1);\r\n ustr += ch;\r\n } else {\r\n unique.put(ch, unique.get(ch) + 1);\r\n }\r\n }\r\n\r\n \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"aab\r\naac\r\naad\r\naae\r\nabb\r\nabc\r\nabd\r\nabe\r\nacc\r\nacd\r\nace\r\nadd\r\nade\r\nbbb\r\nbbc\r\nbbd\r\nbbe\r\nbcc\r\nbcd\r\nbce\r\nbdd\r\nbde\r\nccd\r\ncce\r\ncdd\r\ncde\r\ndde","questionVideo":"","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":"82434199-fab0-48f0-aa58-3491e914eedb","name":"Words - K Selection - 3","slug":"words-k-selection-3","type":1}],"next":{"id":"481c8428-2b4b-4051-afa8-09ab94721b88","name":"Words - K Selection - 3 MCQ","type":0,"slug":"words-k-selection-3-mcq"},"prev":{"id":"64f942e5-1a07-4063-a911-e0d73cb26534","name":"Coin Change - Combinations - 2 MCQ","type":0,"slug":"coin-change-combinations-2-mcq"}}}
plane

Editor


Loading...

Words - K Selection - 3

easy

1. You are given a word (may have one character repeat more than once). 2. You are given an integer k. 2. You are required to generate and print all ways you can select k characters out of the word. 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() < 15 0 < k <= str.length()

Format

Input

Input is managed for you

Output

Check the sample ouput and question video.

Example

Sample Input

aabbbccdde 3

Sample Output

aab aac aad aae abb abc abd abe acc acd ace add ade bbb bbc bbd bbe bcc bcd bce bdd bde ccd cce cdd cde dde

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode