ORIGINAL CODING QUESTION
Integer square-root floor
Return floor(sqrt(x)) without requiring floating-point root operations.
Original exercise · easy. Editorial role relevance does not imply a company has asked this question.
Input and output
One nonnegative integer x.
Constraints
0 ≤ x ≤ 1,000,000,000.
Example 1
Input
8
Output
2
The floor root is 2.
Example 2
Input
16
Output
4
The exact root is 4.
Explain your approach
Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?
Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.
Hint 1
Search candidate roots rather than every number.
Hint 2
Compare mid² with x.
Hint 3
Keep the largest candidate whose square does not exceed x.
Practice this question
Save your work privately, explain decisions and return to your revision queue.
Open practice workspaceBrowse the question library →