VOOZH about

URL: https://www.geeksforgeeks.org/dsa/prime-string/

⇱ Prime String - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Prime String

Last Updated : 11 Jul, 2025

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 : Yes

Input  : GeeksForGeeks
Output : No

Algorithm  

  1. Calculate the string length
  2. Calculate sum of ASCII value of all characters
  3. 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)
  4. If the Sum is Prime then print β€œYes” otherwise β€œNo”

Now the implementation of above approach given below: 


Output
No

Time Complexity: O(n)
Auxiliary Space: O(1), As constant extra space is used.

Comment