Square Root of an Integer Challenge

Given an integer 'A', the objective is to find the largest non-negative integer whose square is less than or equal to 'A'.

The square of a number is defined as the product of the number with itself. For example, the square of 3 is 9.

Example:

Input:
T = 2
A = 10
A = 15
Output:
3
3
Explanation:

For A = 10, 32 = 9 which is ≤ 10, but 42 = 16 which is > 10. Hence, the output is 3. Similarly, for A = 15, the greatest integer whose square is ≤ 15 is 3.

Constraints:

  • 1 ≤ T ≤ 104
  • 0 ≤ A ≤ 105
  • Time Limit: 1 sec
Note:

You do not need to print anything; the necessary functionality to print has already been accounted for. Just carry out the function implementation.

Additional Task:

Consider whether it is possible to compute the square root in O(log(n)) time complexity.

Be the first one to answer
Add answer anonymously...
ShareChat SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter