Given an integer k and a string str consisting of lowercase English alphabets, the task is to count how many k character words (with or without meaning) can be formed from the characters of str when repetition is not allowed.
Input: str = “cat”, k = 3
Required words are “cat”, “cta”, “act”, “atc”, “tca” and “tac”.
Input: str = “geeksforgeeks”, k = 3
Approach: Count the number of distinct characters in str and store it in cnt, now the task is to arrange k characters out of cnt characters i.e. nPr = n! / (n – r)!.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Print all possible strings of length k that can be formed from a set of n characters
- Check if the given string of words can be formed from words present in the dictionary
- Print all permutations with repetition of characters
- Convert to a string that is repetition of a substring of k length
- Strings formed from given characters without any consecutive repeating characters
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Possible Words using given characters in Python
- Group words with same set of characters
- Print all valid words that are possible using Characters of Array
- Python | Toggle characters in words having same case
- Dyck Words of given length
- Java program to swap first and last characters of words in a sentence
- Count of substrings formed using a given set of characters only
- Find words which are greater than given length k
- Generating Lyndon words of length n
- Count of Substrings that can be formed without using the given list of Characters
- Find words which are greater than given length k using stringstream
- Lexicographically largest string formed from the characters in range L and R
- Java program to print Even length words in a String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.