Given an integer N, the task is to generate a string str which contains maximum possible lowercase alphabets with each of them appearing an odd number of times.
Input: N = 17
Explanation: In order to maximize the number of characters, any 17 characters can be selected and made to appear once. Thus, abcdefghijklmnopq, bcdefghijklmnopqx, etc can be also be valid outputs.
Input: N = 35
Explanation: In order to maximize the number of characters, add any 24 different characters once, and fill the remaining length by any other character.
- If N is less than equal to 26, we fill the string by N different characters each appearing once.
- If N is odd, we add all 24 characters from ‘b’-‘y’ once and fill the remaining odd length by ‘a’.
- If N is even, we add all 25 characters from ‘b’-‘z’ once and fill the remaining odd length by ‘a’.
Below is the implementation of the above approach:
- Generate a Number in Decreasing order of Frequencies of characters of a given String
- Maximum distinct lowercase alphabets between two uppercase
- Remove all characters other than alphabets from string
- Check if a string contains only alphabets in Java
- XOR of Prime Frequencies of Characters in a String
- Sub-string that contains all lowercase alphabets after performing the given operation
- Sum and Product of Prime Frequencies of Characters in a String
- Queries to find frequencies of a string within specified substrings
- Check whether the frequencies of all the characters in a string are prime or not
- Check if a string contains only alphabets in Java using ASCII values
- Check if a string contains only alphabets in Java using Lambda expression
- Generate a string whose all K-size substrings can be concatenated to form the given string
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Binary string with given frequencies of sums of consecutive pairs of characters
- Sort an alphanumeric string such that the positions of alphabets and numbers remain unchanged
- Minimize Cost to sort a String in Increasing Order of Frequencies of Characters
- Generate all rotations of a given string
- Program to generate all possible valid IP addresses from given string | Set 2
- Generate random String of given size in Java
- Generate all permutations of a string that follow given constraints
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.