![]() |
VOOZH | about |
Given string s consisting of uppercase and lowercase characters. The task is to sort uppercase and lowercase characters separately such that if the ith place in the original string had an uppercase character, then it should not have a lowercase character after being sorted and vice versa.
Examples:
Input: s = "GEekS"
Output: "EGekS"
Explanation: Sorted form of given string with the same case of character will result in output as EGekS.Input: s = "defRTSersUXI"
Output: "deeIRSfrsTUX"
Explanation: Sorted form of given string with the same case of character as that in original string is deeIRSfrsTUXInput: s = "srbDKi"
Output: "birDKs"
Explanation: Sorted form of given string with the same case of character will result in output as birDKs.
The idea is to sort lowercase and uppercase separately while maintaining their original positions. We store, sort, and then replace characters based on their original case. This ensures the case structure remains unchanged while sorting.
EGekS
The idea is to use two count arrays to count the frequency of each character, avoiding direct sorting. Then, we reconstruct the string by placing characters in their respective positions using the stored frequencies
Step-By-Step Approach:
EGekS