Given a string str, containing upper case and lower case characters. In a single operations, any lowercase character can be converted to an uppercase character and vice versa. The task is to print the minimum number of such operations required so that the resultant string consists of zero or more upper case characters followed by zero or more lower case characters.
Input: str = “geEks”
Either the first 2 characters can be converted to uppercase characters i.e. “GEEks” with 2 operations.
Or the third character can be converted to a lowercase character i.e. “geeks” with a single operation.
Input: str = “geek”
The string is already in the specified format.
Approach: There are two possible cases:
- Find the index of the last uppercase character in the string and convert all the lowercase characters appearing before it into uppercase characters.
- Or, find the index of the first lowercase character in the string and convert all the uppercase characters appearing after it into lowercase characters.
Choose the case where the operations required are minimum.
Below is the implementation of the above approach:
Time Complexity: O(N) where N is the length of the string.
- Minimum operations to make frequency of all characters equal K
- Minimum characters that are to be inserted such that no three consecutive characters are same
- Check if lowercase and uppercase characters are in same order
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Replace minimal number of characters to make all characters pair wise distinct
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Python | Toggle characters in words having same case
- Convert characters of a string to opposite case
- Remove minimum number of characters so that two strings become anagram
- Minimum number of characters to be removed to make a binary string alternate
- Lower case to upper case - An interesting fact
- Minimum move to end operations to make all strings equal
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Min flips of continuous characters to make all characters same in a string
- String with k distinct characters and no same characters adjacent
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.