Write a function to find the square root of a number using the binary search approach.
HardProblem 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)}")
}
Input
A hardcoded number, e.g., 25.
Expected Output
Square root of 25 is: 5