{"id":"32fec378-3204-448a-bf48-ca4711fe2b8b","name":"Words - K Length Words - 2","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 k length words (of distinct chars) by using chars 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\n void generateWords(int cs, int ts, string ustr, set<char>& used, string asf) \n {\n //write your code here\n }\n \n int main()\n {\n string str;\n int k;\n cin>>str;\n set<char> unique;\n string ustr = \"\";\n for(int i=0;i<str.length();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 set<char>used;\n generateWords(1, k, ustr, used, \"\");\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 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 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 \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"abc\r\nabd\r\nabe\r\nacb\r\nacd\r\nace\r\nadb\r\nadc\r\nade\r\naeb\r\naec\r\naed\r\nbac\r\nbad\r\nbae\r\nbca\r\nbcd\r\nbce\r\nbda\r\nbdc\r\nbde\r\nbea\r\nbec\r\nbed\r\ncab\r\ncad\r\ncae\r\ncba\r\ncbd\r\ncbe\r\ncda\r\ncdb\r\ncde\r\ncea\r\nceb\r\nced\r\ndab\r\ndac\r\ndae\r\ndba\r\ndbc\r\ndbe\r\ndca\r\ndcb\r\ndce\r\ndea\r\ndeb\r\ndec\r\neab\r\neac\r\nead\r\neba\r\nebc\r\nebd\r\neca\r\necb\r\necd\r\neda\r\nedb\r\nedc","questionVideo":"https://www.youtube.com/embed/_geihPcxPag?end=308","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":"efbd0d37-3ade-4a9b-a966-a2115cf0b103","name":"Words - K Length Words - 2","slug":"words-k-length-words-2","type":1}],"next":{"id":"58eaeac9-066e-4e2c-a9df-ec3135d4948e","name":"Words-K-length words-2 MCQ","type":0,"slug":"words-k-length-words-2-mcq"},"prev":{"id":"593db8c4-8626-455f-8509-de7592b0838b","name":"words-k-length-words-1 MCQ","type":0,"slug":"words-k-length-words-1-mcq"}}}

Words - K Length Words - 2

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 k length words (of distinct chars) by using chars 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":"32fec378-3204-448a-bf48-ca4711fe2b8b","name":"Words - K Length Words - 2","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 k length words (of distinct chars) by using chars 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\n void generateWords(int cs, int ts, string ustr, set<char>& used, string asf) \n {\n //write your code here\n }\n \n int main()\n {\n string str;\n int k;\n cin>>str;\n set<char> unique;\n string ustr = \"\";\n for(int i=0;i<str.length();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 set<char>used;\n generateWords(1, k, ustr, used, \"\");\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 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 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 \r\n }\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"aabbbccdde\r\n3","sampleOutput":"abc\r\nabd\r\nabe\r\nacb\r\nacd\r\nace\r\nadb\r\nadc\r\nade\r\naeb\r\naec\r\naed\r\nbac\r\nbad\r\nbae\r\nbca\r\nbcd\r\nbce\r\nbda\r\nbdc\r\nbde\r\nbea\r\nbec\r\nbed\r\ncab\r\ncad\r\ncae\r\ncba\r\ncbd\r\ncbe\r\ncda\r\ncdb\r\ncde\r\ncea\r\nceb\r\nced\r\ndab\r\ndac\r\ndae\r\ndba\r\ndbc\r\ndbe\r\ndca\r\ndcb\r\ndce\r\ndea\r\ndeb\r\ndec\r\neab\r\neac\r\nead\r\neba\r\nebc\r\nebd\r\neca\r\necb\r\necd\r\neda\r\nedb\r\nedc","questionVideo":"https://www.youtube.com/embed/_geihPcxPag?end=308","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":"efbd0d37-3ade-4a9b-a966-a2115cf0b103","name":"Words - K Length Words - 2","slug":"words-k-length-words-2","type":1}],"next":{"id":"58eaeac9-066e-4e2c-a9df-ec3135d4948e","name":"Words-K-length words-2 MCQ","type":0,"slug":"words-k-length-words-2-mcq"},"prev":{"id":"593db8c4-8626-455f-8509-de7592b0838b","name":"words-k-length-words-1 MCQ","type":0,"slug":"words-k-length-words-1-mcq"}}}
plane

Editor


Loading...

Words - K Length Words - 2

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 k length words (of distinct chars) by using chars 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 acb acd ace adb adc ade aeb aec aed bac bad bae bca bcd bce bda bdc bde bea bec bed cab cad cae cba cbd cbe cda cdb cde cea ceb ced dab dac dae dba dbc dbe dca dcb dce dea deb dec eab eac ead eba ebc ebd eca ecb ecd eda edb edc

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode