VOOZH about

URL: https://www.geeksforgeeks.org/dsa/perfect-square-string/

⇱ Perfect Square String - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Perfect Square String

Last Updated : 11 Jul, 2025

Given a String str and the task is to check sum of ASCII value of all characters is a perfect square or not.

Examples : 

Input : ddddddddddddddddddddddddd
Output : Yes

Input : GeeksForGeeks
Output : No

Recommended Practice

Algorithm  

  • Calculate the string length
  • Calculate sum of ASCII value of all characters
  • Take the square root of the number sum and store it into variable squareRoot
  • Take floor value of the squareRoot and subtract from squareRoot
  • If the difference of floor value of squareRoot and squareRoot is 0 then print "Yes" otherwise "No"

Below is the implementation of the above approach : 


Output
Yes

Time Complexity: O(len), where the len is the length of the string.
Auxiliary Space: O(1)

Comment