{"id":"deda4272-6301-4512-b516-14a43b0a9001","name":"Words - K Selection - 1","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 distinct characters out of the \r\n word.\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; 15\r\n0 &lt; k &lt;= str.length()","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvoid combination(int i, string ustr, int ssf, int ts, string asf )\n{\n // WRITE YOUR CODE HERE\n}\nint main()\n{\n string str;\n cin>>str;\n int k;\n cin>>k;\n \n set<char> unique;\n string ustr=\"\";\n for(int i=0;i<str.size();i++)\n {\n char ch=str[i];\n if(unique.find(ch)==unique.end())\n {\n unique.insert(ch);\n ustr+=ch;\n }\n }\n combination(0, ustr, 0, k, \"\");\n return 0;\n}"},"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 Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n int k = scn.nextInt();\r\n\r\n HashSet<Character> unique = new HashSet<>();\r\n String ustr = \"\";\r\n for (char ch : str.toCharArray()) {\r\n if (unique.contains(ch) == false) {\r\n unique.add(ch);\r\n ustr += ch;\r\n }\r\n }\r\n\r\n combination(0, ustr, 0, k, \"\");\r\n }\r\n\r\n\r\n public static void combination(int i, String ustr, int ssf, int ts, String asf ) {\r\n\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"abc\r\nabd\r\nabe\r\nacd\r\nace\r\nade\r\nbcd\r\nbce\r\nbde\r\ncde","questionVideo":"https://www.youtube.com/embed/PiwttDa5FMA?end=432","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":"39553192-62c9-40e2-8ee7-b60335948ab2","name":"Words - K Selection - 1","slug":"words-k-selection-1","type":1}],"next":{"id":"7aef3448-e6d0-4327-a365-09f0891c71e7","name":"words-k-selection-1 MCQ","type":0,"slug":"words-k-selection-1-mcq"},"prev":{"id":"9c309b80-dfcd-4aee-92c0-3082fd38e26f","name":"Permutations-words-2 MCQ","type":0,"slug":"permutations-words-2-mcq"}}}

Words - K Selection - 1

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 distinct 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":"deda4272-6301-4512-b516-14a43b0a9001","name":"Words - K Selection - 1","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 distinct characters out of the \r\n word.\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; 15\r\n0 &lt; k &lt;= str.length()","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\n\nvoid combination(int i, string ustr, int ssf, int ts, string asf )\n{\n // WRITE YOUR CODE HERE\n}\nint main()\n{\n string str;\n cin>>str;\n int k;\n cin>>k;\n \n set<char> unique;\n string ustr=\"\";\n for(int i=0;i<str.size();i++)\n {\n char ch=str[i];\n if(unique.find(ch)==unique.end())\n {\n unique.insert(ch);\n ustr+=ch;\n }\n }\n combination(0, ustr, 0, k, \"\");\n return 0;\n}"},"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 Scanner scn = new Scanner(System.in);\r\n String str = scn.nextLine();\r\n int k = scn.nextInt();\r\n\r\n HashSet<Character> unique = new HashSet<>();\r\n String ustr = \"\";\r\n for (char ch : str.toCharArray()) {\r\n if (unique.contains(ch) == false) {\r\n unique.add(ch);\r\n ustr += ch;\r\n }\r\n }\r\n\r\n combination(0, ustr, 0, k, \"\");\r\n }\r\n\r\n\r\n public static void combination(int i, String ustr, int ssf, int ts, String asf ) {\r\n\r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"abc\r\nabd\r\nabe\r\nacd\r\nace\r\nade\r\nbcd\r\nbce\r\nbde\r\ncde","questionVideo":"https://www.youtube.com/embed/PiwttDa5FMA?end=432","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":"39553192-62c9-40e2-8ee7-b60335948ab2","name":"Words - K Selection - 1","slug":"words-k-selection-1","type":1}],"next":{"id":"7aef3448-e6d0-4327-a365-09f0891c71e7","name":"words-k-selection-1 MCQ","type":0,"slug":"words-k-selection-1-mcq"},"prev":{"id":"9c309b80-dfcd-4aee-92c0-3082fd38e26f","name":"Permutations-words-2 MCQ","type":0,"slug":"permutations-words-2-mcq"}}}
plane

Editor


Loading...

Words - K Selection - 1

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 distinct 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

abc abd abe acd ace ade bcd bce bde cde

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode