Given alphanumeric string str, the task is to check if the count of Alphabets and count of Numbers are equal or not.
Input: str = “GeeKs01234”
The count of alphabets and numbers are equal to 5.
Input: str = “Gfg01234”
The count of alphabets are 3 whereas the count of numbers are 5.
Approach: The idea is to use the ASCII values of the characters to distinguish between a number and an alphabet. After distinguishing the characters, two counters are maintained to count the number of alphabets and numbers respectively. Finally, both the counters are checked for equality.
The ASCII ranges of the characters are as follows:
- Lowercase characters: 97 to 122
- Uppercase characters: 65 to 90
- Digits: 48 to 57
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check whether count of odd and even factors of a number are equal
- Check if count of even divisors of N is equal to count of odd divisors
- Count number of equal pairs in a string
- Count ways to partition a string such that both parts have equal distinct characters
- Count of alphabets having ASCII value less than and greater than k
- Count and Print the alphabets having ASCII value in the range [l, r]
- Count and Print the alphabets having ASCII value not in the range [l, r]
- Check if a string contains only alphabets in Java
- Count of character pairs at same distance as in English alphabets
- Check whether count of distinct characters in a string is Prime or not
- For each lowercase English alphabet find the count of strings having these alphabets
- Check if a string contains only alphabets in Java using Lambda expression
- Check if a string contains only alphabets in Java using ASCII values
- Sort an alphanumeric string such that the positions of alphabets and numbers remain unchanged
- Count of sub-strings with equal consecutive 0's and 1's
- Count Substrings with equal number of 0s, 1s and 2s
- Count of Nodes in a LinkedList whose value is equal to their frequency
- Count of substrings whose Decimal equivalent is greater than or equal to K
- Count of pairs upto N such whose LCM is not equal to their product for Q queries
- Check whether the string S1 can be made equal to S2 with the given operation
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.