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)
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 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
- Check if count of Alphabets and count of Numbers are equal in the given String
- Print the Alphabets A to Z in Star Pattern
- 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 pairs of characters in a string whose ASCII value difference is K
- Count characters in a string whose ASCII values are prime
- Count the number of words having sum of ASCII values less than and greater than k
- For each lowercase English alphabet find the count of strings having these alphabets
- Program to print all palindromes in a given range
- Queries to print the character that occurs the maximum number of times in a given range
- Count Unary Numbers in a Range
- Count of numbers in a range that does not contain the digit M and which is divisible by M.
- Count of Palindromic substrings in an Index range
- Count number of distinct sum subsets within given range
- Count of Numbers in Range where the number does not contain more than K non zero digits
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.