{"id":"971f3104-e09b-418d-87be-29922102c8c0","name":"Words - K Selection - 4","description":"1. You are given a word (may have one character repeat more than once).\r\n2. You are given an integer k.\r\n3. 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":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nvoid generateSelection(int cs, int ts, string ustr, unordered_map<char, int> &unique, int ls, string asf) {\n //Write your code here\n }\n\n\nint main(){\n string str ;\n cin>>str ;\n int k ;\n cin>>k ;\n unordered_map<char, int> unique;\n string ustr = \"\" ;\n vector<char> arr(str.length()) ;\n for(int i =0 ; i<str.length(); i++)\n {\n arr[i] = str.at(i) ;\n }\n \n for(int i =0 ; i<arr.size() ; i++)\n {\n char ch = arr[i] ;\n if(unique.find(ch)== unique.end()){\n unique.insert({ch , 1}) ;\n ustr+=ch ;\n }else{\n unique.insert({ch , (unique.at(ch)++)}) ;\n }\n }\n generateSelection(1 , k , ustr , unique , 0 , \"\") ;\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\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":"dd7598a5-7a2b-4645-bb45-d4b315e3f187","name":"Words - K Selection - 4","slug":"words-k-selection-4","type":1}],"next":{"id":"63970140-c40b-453f-9db5-bb97e97678a8","name":"Words - K Selection - 4 MCQ","type":0,"slug":"words-k-selection-4-mcq"},"prev":{"id":"481c8428-2b4b-4051-afa8-09ab94721b88","name":"Words - K Selection - 3 MCQ","type":0,"slug":"words-k-selection-3-mcq"}}}

Words - K Selection - 4

1. You are given a word (may have one character repeat more than once). 2. You are given an integer k. 3. 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":"971f3104-e09b-418d-87be-29922102c8c0","name":"Words - K Selection - 4","description":"1. You are given a word (may have one character repeat more than once).\r\n2. You are given an integer k.\r\n3. 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":"#include<bits/stdc++.h>\nusing namespace std;\n\n\nvoid generateSelection(int cs, int ts, string ustr, unordered_map<char, int> &unique, int ls, string asf) {\n //Write your code here\n }\n\n\nint main(){\n string str ;\n cin>>str ;\n int k ;\n cin>>k ;\n unordered_map<char, int> unique;\n string ustr = \"\" ;\n vector<char> arr(str.length()) ;\n for(int i =0 ; i<str.length(); i++)\n {\n arr[i] = str.at(i) ;\n }\n \n for(int i =0 ; i<arr.size() ; i++)\n {\n char ch = arr[i] ;\n if(unique.find(ch)== unique.end()){\n unique.insert({ch , 1}) ;\n ustr+=ch ;\n }else{\n unique.insert({ch , (unique.at(ch)++)}) ;\n }\n }\n generateSelection(1 , k , ustr , unique , 0 , \"\") ;\n \n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\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":"dd7598a5-7a2b-4645-bb45-d4b315e3f187","name":"Words - K Selection - 4","slug":"words-k-selection-4","type":1}],"next":{"id":"63970140-c40b-453f-9db5-bb97e97678a8","name":"Words - K Selection - 4 MCQ","type":0,"slug":"words-k-selection-4-mcq"},"prev":{"id":"481c8428-2b4b-4051-afa8-09ab94721b88","name":"Words - K Selection - 3 MCQ","type":0,"slug":"words-k-selection-3-mcq"}}}
plane

Editor


Loading...

Words - K Selection - 4

easy

1. You are given a word (may have one character repeat more than once). 2. You are given an integer k. 3. 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