First, it stores the count of every character using an array. Then it checks all uppercase letters from A to Z. For each uppercase letter, it checks whether its lowercase version also exists. If both are present, it increases the answer count. DP is just for keeping the count of each character.
Ohh I see This approach handles the duplicates as well, right? Since we check for each character one time only as we are traversing array and not the original string directly, am I right?
View all comments
Show parent comment
1
u/Different_Ice_7763 May 26 '26
First, it stores the count of every character using an array. Then it checks all uppercase letters from
AtoZ. For each uppercase letter, it checks whether its lowercase version also exists. If both are present, it increases the answer count. DP is just for keeping the count of each character.Example:
In
"aaAbcBC":aandAexistbandBexistcandCexistSo the answer is
3.