FastPrepInteger Square Root
Problems/Integer Square Root

Integer Square Root

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was a technical interview round of a Microsoft software engineering internship process, per a review. The round is said to have lasted about fifty minutes. The task as reported is to compute a number's square root. That round also had a check for a valid binary search tree.

The review does not say what kind of number, how to round, or whether library functions are allowed. Here x is a non-negative integer up to 2^31 - 1, you return its square root rounded down as an integer, and built-in square root or power functions are off limits (the judge does not check this).

Our version is about 80% the same as the reported question.

Given a non-negative integer x, return the square root of x rounded down to the nearest integer. In other words, return the largest integer r such that r * r <= x.

Do not use a built-in square root or power function. The judge checks only the returned value, so this rule is not checked automatically.

Function

mySqrt(x: int) → int

Examples

Example 1

x = 10return = 3

3 * 3 = 9 is at most 10, but 4 * 4 = 16 is more than 10. The square root of 10 is about 3.16, and rounding down gives 3.

Example 2

x = 49return = 7

49 is a perfect square: 7 * 7 = 49, so the answer is exactly 7.

Example 3

x = 0return = 0

The square root of 0 is 0.

Constraints

  • 0 <= x <= 2^31 - 1

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Integer Square Root with Error ChecksBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Random Pick with Weight Using Recorded DrawsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Koko Eating BananasTekion · ONSITE INTERVIEWTekion interview questions
  • Koko Eating BananasAmazon · ONSITE INTERVIEW
  • Maximum Supplier ProfitExpedia · ONSITE INTERVIEWExpedia interview questions
  • K-th Amount a Payout Machine Can GiveRippling · ONSITE INTERVIEWRippling interview questions
  • First Register Overflow TickNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
  • Two Eggs: Minimum Worst-Case DropsApple · ONSITE INTERVIEWApple interview questions
  • Find a Function Root by BisectionJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Pressure Chamber Linear InterpolationSpaceX · PHONE SCREENSpaceX interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int mySqrt(int x) {
        // Write your code here.
    }
}
Checking account…