![]() |
VOOZH | about |
Check if a given number N is a perfect square or not. If yes then return the number of which it is a perfect square, Else print -1.
Examples:
Input: N = 4900
Output 70
Explanation:
4900 is a perfect square number of 70 because 70 * 70 = 4900Input: N = 81
Output: 9
Explanation:
81 is a perfect square number of 9 because 9 * 9 = 81
Approach: To solve the problem mentioned above we will use the Binary Search Algorithm.
Below is the implementation of above approach:
-1
Time Complexity: O(Logn)
Auxiliary Space: O(Logn) for recursive stack space.