Find the Nth Root of a Number

Binary Search on Answers DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Finding the Nth Root of a Number M (If Integer, Else Return -1), Linear Search, Binary Search, Mathematical Algorithms, Time Complexity, Space Complexity, Loops, Conditional Statements, complexity analysis, brute force, number properties, binary search, exponentiation, Binary Exponentiation, Number Manipulation.

Problem Statement Given two positive integers N and M, find the N th root of M. The N th root of a number M is defined as a number X such that X raised to the power N equals M (i.e., X^N = M). If the N th root is not an integer, return 1. Examples Example 1: Explanation: The cube root of 27 is equal to 3 (since 3^3 = 27). Example 2: Explanation: The 4th root of 69 does not exist as an integer.