Given a string str containing lower case alphabets and character ‘?’. The task is to check if it is possible to make str good or not.
A string is called good if it contains a sub-string of length 26 which has every character of lower case alphabets in it.
The task is to check if it is possible to make the string good by replacing ‘?’ characters with any lower case alphabet. If it is possible then print the modified string otherwise print -1.
Input: str = “abcdefghijkl?nopqrstuvwxy?”
Replace first ‘?’ with ‘m’ and second with ‘z’.
Input: str = “abcdefghijklmnopqrstuvwxyz??????”
Given string already has a sub-string which contains all the 26 lower case alphabets.
Approach: If the length of the string is less than 26 then print -1. The Task is to make a sub-string of length 26 that has all the lowercase characters. Thus, the simplest way is to iterate through all sub-strings of length 26 then for each sub-string count the number of occurrences of each alphabet, ignoring the question marks. After that, if there exists a character that occurs twice or more then this sub-string cannot contain all letters of the alphabet, and we process the next sub-string. Otherwise, we can fill in the question marks with the letters that have not appeared in the sub-string and obtain a sub-string of length 26 which contains all letters of the alphabet.
Below is the implementation of the above approach:
- Maximum distinct lowercase alphabets between two uppercase
- Sum of the updated array after performing the given operation
- Minimum possible sum of array elements after performing the given operation
- Find the index which is the last to be reduced to zero after performing a given operation
- Check if the last element of array is even or odd after performing a operation p times
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Check if lowercase and uppercase characters are in same order
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Count Uppercase, Lowercase, special character and numeric values
- Final string after performing given operations
- Maximum Possible Product in Array after performing given Operations
- Number of odd and even results for every value of x in range [min, max] after performing N steps
- Maximum sum of all elements of array after performing given operations
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.