Find Square Root of a Number in log N
Binary Search on Answers DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Finding the Floor of the Square Root of a Positive Integer, Linear Search, Binary Search, Time Complexity, Space Complexity, Mathematical Algorithms, complexity analysis, mathematical functions, divide and conquer, search algorithms, binary search, Mathematical Operations, Time & Space Complexity Analysis.
S Problem: Square Root of an Integer (Floor) Problem Statement You are given a positive integer n. Your task is to find and return its square root. If n is not a perfect square, then return the floor value of sqrt(n). This means you need to determine the maximum integer x such that x x <= n. Input Specification A single positive integer n. Output Specification Return an integer representing the floor of the square root of n. Constraints 1 <= n <= 10^18 Sample Test Cases Example 1: Input: n = 36 Output: 6 Explanation: 6 is the square root of 36. Example 2: Input: n = 28 Output: 5 Explanation: Square root of 28 is approximately 5.292. The floor value is 5.