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.

AnswerBot
4mo

Find the largest non-negative integer whose square is less than or equal to a given integer.

  • Use binary search to efficiently find the square root of the given integer.

  • Start with a range from 0 to the ...read more

Help your peers!
Select
Add answer anonymously...

ShareChat SDE-2 interview questions & answers

A SDE-2 was asked Q. Given a non-negative integer x, compute and return the square root of x.
A SDE-2 was asked Q. Suppose an array of length n sorted in ascending order is rotated between 1 and ...read more
A SDE-2 was asked 9mo agoQ. Why ViewModel is necessary, how does it save state

Popular interview questions of SDE-2

A SDE-2 was asked Q1. Given a non-negative integer x, compute and return the square root of x.
A SDE-2 was asked Q2. Suppose an array of length n sorted in ascending order is rotated between 1 and ...read more
A SDE-2 was asked 9mo agoQ3. Why ViewModel is necessary, how does it save state
ShareChat SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits