We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am able to understand your logic. But instead of using the ceil and floor functions I tried saving the sqrt values in int so that the values after decimal is neglected. For example, for [3,10] sqrt(3) gives 1 and sqrt(10) gives 3 when stored in int. Their difference gives the correct answer 2. But it doesn't work in some cases. I am not able to understand what is difference in my logic and the ceil-floor logic.
P.S. I included a case if both numbers are equal. Ex [4,4] so it is certainly not an issue.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
I am able to understand your logic. But instead of using the ceil and floor functions I tried saving the sqrt values in int so that the values after decimal is neglected. For example, for [3,10] sqrt(3) gives 1 and sqrt(10) gives 3 when stored in int. Their difference gives the correct answer 2. But it doesn't work in some cases. I am not able to understand what is difference in my logic and the ceil-floor logic. P.S. I included a case if both numbers are equal. Ex [4,4] so it is certainly not an issue.