Given a string, the task is to count the number of alphabets having ASCII value less than and greater than or equal to a given integer k.
Input: str = "GeeksForGeeks", k = 90 Output: 3, 10 G, F, G have ascii values less than 90. e, e, k, s, o, r, e, e, k, s have ascii values greater than or equal to 90 Input: str = "geeksforgeeks", k = 90 Output: 0, 13
Approach: Start traversing the string and check if the current character has ASCII value less than k. If yes then increment the count.
So, Remaining characters will have ASCII values greater than or equal to k. So, print len_of_String – count for characters with ASCII values greater than or equal to k.
Below is the implementation of the above approach:
Characters with ASCII values less than K are 3 Characters with ASCII values greater than or equal to K are 10
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 the number of words having sum of ASCII values 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]
- Sub-strings having exactly k characters that have ASCII value greater than p
- 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
- Convert Hexadecimal value String to ASCII value String
- Replace every character of string by character whose ASCII value is K times more than it
- Count pairs of characters in a string whose ASCII value difference is K
- Count of integers of length N and value less than K such that they contain digits only from the given set
- Check if count of Alphabets and count of Numbers are equal in the given String
- Find the length of the longest subsequence with first K alphabets having same frequency
- Longest sub-string having frequency of each character less than equal to k
- 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
- Program to print ASCII Value of a character
- Convert the ASCII value sentence to its equivalent string
- Total character pairs from two strings, with equal number of set bits in their ascii value
- Convert all lowercase characters to uppercase whose ASCII value is co-prime with k
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Remove all characters other than alphabets from string
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.