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:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- 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 of binary strings of length N having equal count of 0's and 1's
- 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
- Check if a string contains only alphabets in Java
- Count and Print the alphabets having ASCII value not in the range [l, r]
- Count and Print the alphabets having ASCII value in the range [l, r]
- Count of character pairs at same distance as in English alphabets
- Check whether count of distinct characters in a string is Prime or not
- Check if a string contains only alphabets in Java using Lambda expression
- Check if a string contains only alphabets in Java using ASCII values
- For each lowercase English alphabet find the count of strings having these alphabets
- 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 pairs upto N such whose LCM is not equal to their product for Q queries
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.