{"id":"6ec33bbb-0273-419d-9155-bbe596344873","name":"Words - K Length Words - 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\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\nvoid generateWords(int cc, string ustr,int ssf,int ts,vector<char>spots){\n //write your code here\n}\nint main(){\n string str;\n cin>>str;\n int k;\n cin>>k;\n set<char>unique;\n string ustr=\"\";\n for(int i=0;i<str.length();i++){\n if(unique.find(str[i])==unique.end()){\n unique.insert(str[i]);\n ustr+=str[i];\n }\n }\n vector<char>spots(k,NULL);\n generateWords(0,ustr,0,k,spots);\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 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\nadb\r\naeb\r\nacd\r\nace\r\nadc\r\naec\r\nade\r\naed\r\nbac\r\nbad\r\nbae\r\ncab\r\ndab\r\neab\r\ncad\r\ncae\r\ndac\r\neac\r\ndae\r\nead\r\nbca\r\nbda\r\nbea\r\ncba\r\ndba\r\neba\r\ncda\r\ncea\r\ndca\r\neca\r\ndea\r\neda\r\nbcd\r\nbce\r\nbdc\r\nbec\r\nbde\r\nbed\r\ncbd\r\ncbe\r\ndbc\r\nebc\r\ndbe\r\nebd\r\ncdb\r\nceb\r\ndcb\r\necb\r\ndeb\r\nedb\r\ncde\r\nced\r\ndce\r\necd\r\ndec\r\nedc","questionVideo":"https://www.youtube.com/embed/ZmAoj7wpMvM?end=531","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":"891caa53-b9fa-482e-82ef-29aef27b5726","name":"Words - K Length Words - 1","slug":"words-k-length-words-1","type":1}],"next":{"id":"593db8c4-8626-455f-8509-de7592b0838b","name":"words-k-length-words-1 MCQ","type":0,"slug":"words-k-length-words-1-mcq"},"prev":{"id":"ab776e0b-3f43-47c8-8779-35401e13e35f","name":"Words-k-selection-2 MCQ","type":0,"slug":"words-k-selection-2-mcq"}}}

Words - K Length Words - 1

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":"6ec33bbb-0273-419d-9155-bbe596344873","name":"Words - K Length Words - 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\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\nvoid generateWords(int cc, string ustr,int ssf,int ts,vector<char>spots){\n //write your code here\n}\nint main(){\n string str;\n cin>>str;\n int k;\n cin>>k;\n set<char>unique;\n string ustr=\"\";\n for(int i=0;i<str.length();i++){\n if(unique.find(str[i])==unique.end()){\n unique.insert(str[i]);\n ustr+=str[i];\n }\n }\n vector<char>spots(k,NULL);\n generateWords(0,ustr,0,k,spots);\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 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\nadb\r\naeb\r\nacd\r\nace\r\nadc\r\naec\r\nade\r\naed\r\nbac\r\nbad\r\nbae\r\ncab\r\ndab\r\neab\r\ncad\r\ncae\r\ndac\r\neac\r\ndae\r\nead\r\nbca\r\nbda\r\nbea\r\ncba\r\ndba\r\neba\r\ncda\r\ncea\r\ndca\r\neca\r\ndea\r\neda\r\nbcd\r\nbce\r\nbdc\r\nbec\r\nbde\r\nbed\r\ncbd\r\ncbe\r\ndbc\r\nebc\r\ndbe\r\nebd\r\ncdb\r\nceb\r\ndcb\r\necb\r\ndeb\r\nedb\r\ncde\r\nced\r\ndce\r\necd\r\ndec\r\nedc","questionVideo":"https://www.youtube.com/embed/ZmAoj7wpMvM?end=531","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":"891caa53-b9fa-482e-82ef-29aef27b5726","name":"Words - K Length Words - 1","slug":"words-k-length-words-1","type":1}],"next":{"id":"593db8c4-8626-455f-8509-de7592b0838b","name":"words-k-length-words-1 MCQ","type":0,"slug":"words-k-length-words-1-mcq"},"prev":{"id":"ab776e0b-3f43-47c8-8779-35401e13e35f","name":"Words-k-selection-2 MCQ","type":0,"slug":"words-k-selection-2-mcq"}}}
plane

Editor


Loading...

Words - K Length Words - 1

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

Question Video

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode