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.
- Check if the given string of words can be formed from words present in the dictionary
- Count of ways in which N can be represented as sum of Fibonacci numbers without repetition
- Strings formed from given characters without any consecutive repeating characters
- Count of Substrings that can be formed without using the given list of Characters
- Distributing all balls without repetition
- Print all permutations with repetition of characters
- Print all possible strings of length k that can be formed from a set of n characters
- Convert to a string that is repetition of a substring of k length
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Check if a given string can be formed using characters of adjacent cells of a Matrix
- Minimum length of the sub-string whose characters can be used to form a palindrome of length K
- All possible strings of any length that can be formed from a given string
- Check whether second string can be formed from characters of first string
- Number of ways in which the substring in range [L, R] can be formed using characters out of the range
- Count of times second string can be formed from the characters of first string
- Count words that appear exactly two times in an array of words
- Ways to sum to N using array elements with repetition allowed
- Find the count of numbers that can be formed using digits 3, 4 only and having length at max N.
- Maximize count of strings of length 3 that can be formed from N 1s and M 0s
- Length of the longest substring without repeating characters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.