Given a range of integers [A…B] you have to find the maximum no. of repeated square root operations that can be applied on a no. in the range.
Ex: A=10 B=20 sqrt(16)=4 sqrt(4)=2 Ans=2
2 is the maximum no. or repeated square root operations that you can have for the given range.
EX: A=6000 B=7000 sqrt(6561)=81 sqrt(81)=9 sqrt(9)=3
3 is the maximum no. or repeated square root operations that you can have for the given range.
my solution: https://pastebin.com/Pgak4xM8
complexity of my solution: O(M sqrt(N))
M: no. of perfect squares in the range 2..1000000000 N: max value in the range
What could be the most optimized way to solve this problem?
is there any chance of improvement in this?