Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function to find the square root of a number using the binary search approach.

Hard

Problem Statement

Write a function to find the square root of a number using the binary search approach.

Sample Input

A hardcoded number, e.g., 25.

Sample Output

Square root of 25 is: 5

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
fun sqrtBinarySearch(x: Int): Int { // Add your code here to find the square root using binary search } fun main() { val x = 25 println("Square root of $x is: ${sqrtBinarySearch(x)}") }
Log in or sign up to run or submit your code.Log inSign up
Input
A hardcoded number, e.g., 25.
Expected Output
Square root of 25 is: 5