Given two numbers as strings, find if one is a power of other
Given two large numbers as strings, find if one is the power of another.
Input : a = "374747", b = "52627712618930723" Output : YES Explanation : 374747^3 = 52627712618930723 Input : a = "2", b = "4099" Output : NO
Prerequisite: Multiply two large numbers represented as string The approach is simple. First, find smaller of the two strings and then multiply it with itself until it becomes equal to or greater than the larger string. If they are equal, return true, else return false. Below is the implementation of above approach
- Time complexity : O(n*m) where n and m are the sizes of the respective input strings.
- Auxiliary Space : O(n+m) where n and m are the sizes of the respective input strings.
My Personal Notes arrow_drop_up
Please Login to comment...