Given a string, the task is to count the number of words whose sum of Ascii values is less than and greater than or equal to given k.
Input: str = "Learn how to code", k = 400 Output: Number of words having sum of ascii less than k = 2 Number of words having sum of ascii greater than or equal to k = 2 Input: str = "Geeks for Geeks", k = 400 Output: Number of words having sum of ascii less than k = 1 Number of words having sum of ascii greater than or equal to k = 2
Approach: Count the number of words having the sum of ASCII values less than k and subtract it from the total number of words to get the number of words having ASCII values to the sum greater than or equal to k. Start traversing the string letter by letter and add the ASCII value to sum. If there is a space then increment the count if the sum is less than k and will also set the sum to 0.
Below is the implementation of the above approach:
Number of words having sum of ASCII values less than k = 2 Number of words having sum of ASCII values greater than or equal to k = 2
Time Complexity: O(N)
- Count of alphabets having ASCII value less than and greater than k
- Count characters in a string whose ASCII values are prime
- Sub-strings having exactly k characters that have ASCII value greater than p
- Sums of ASCII values of each word in a sentence
- Map function and Dictionary in Python to sum ASCII values
- Convert a string to hexadecimal ASCII values
- Average of ASCII values of characters of a given string
- Print each word in a sentence with their corresponding average of ASCII values
- Check if a string contains only alphabets in Java using ASCII values
- Minimize ASCII values sum after removing all occurrences of one character
- Find the sum of the ascii values of characters which are present at prime positions
- Program to find the product of ASCII values of characters in a string
- Count words that appear exactly two times in an array of words
- Count number of substrings with numeric value greater than X
- Find words which are greater than given length k
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.