![]() |
VOOZH | about |
Given a String str , the task is to check if the sum of ASCII value of all characters is a Prime Number or not.
Examples :
Input : geeksforgeeks
Output : YesInput : GeeksForGeeks
Output : No
Algorithm
- Calculate the string length
- Calculate sum of ASCII value of all characters
- Now we can check till n1/2 because a larger factor of n must be a multiple of smaller factor. (Please see Check If the Number is Prime or Not for details)
- If the Sum is Prime then print βYesβ otherwise βNoβ
Now the implementation of above approach given below:
No
Time Complexity: O(n)
Auxiliary Space: O(1), As constant extra space is used.