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)
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 alphabets having ASCII value less than and greater than k
- Sub-strings having exactly k characters that have ASCII value greater than p
- Map function and Dictionary in Python to sum ASCII values
- 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]
- Count characters in a string whose ASCII values are prime
- 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
- Split a given string into substrings of length K with equal sum of ASCII values
- Count words that appear exactly two times in an array of words
- Find words which are greater than given length k using stringstream
- Find words which are greater than given length k
- Count of Numbers such that difference between the number and sum of its digits not less than L
- Average of ASCII values of characters of a given string
- Check if a string contains only alphabets in Java using ASCII values
- Program to find the product of ASCII values of characters in a string
- Print each word in a sentence with their corresponding average of ASCII values
- Program to find the XOR of ASCII values of characters in a string
- Convert a string to hexadecimal ASCII values
- Sums of ASCII values of each word in a sentence
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.