Given a string str, the task is to count the number of alphabets having ascii in the range [l, r].
Input: str = "geeksforgeeks" l = 102, r = 111 Output: Count = 6, Characters = g, f, k, o Characters - g, f, k, o have ascii values in the range [102, 111]. Input: str = "GeEkS" l = 80, r = 111 Output: Count = 3, Characters = e, k, S
Approach: Start traversing the string and check if the current character has ASCII value less than equal to r and greater than equal to l. If yes then increment the count and print that element.
Below is the implementation of above approach:
Characters with ASCII values in the range [l, r] are g k f o g k and their count is 6
Time Complexity – O(N)
- Count and Print the alphabets having ASCII value not in the range [l, r]
- Count of alphabets having ASCII value less than and greater than k
- Check if a string contains only alphabets in Java using ASCII values
- Program to print ASCII Value of a character
- Print given sentence into its equivalent ASCII form
- Print each word in a sentence with their corresponding average of ASCII values
- Count of character pairs at same distance as in English alphabets
- Count the number of words having sum of ASCII values less than and greater than k
- Count pairs of characters in a string whose ASCII value difference is K
- Count characters in a string whose ASCII values are prime
- Program to print all palindromes in a given range
- Count Unary Numbers in a Range
- Queries to print the character that occurs the maximum number of times in a given range
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count of Palindromic substrings in an Index range
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.