Base Conversion LeetCode

Problem: Given a number in string in base b1, convert it to a base b2 number.

Solution 1:
1)Apply b1 to get the decimal form of the given number
2)Apply b2 to get the desired answer

In this, we just repeatedly use the division and modulus operators
Complexity: O(N + N*log_b2(b1)), where N is the length of the given N number in string.

This problem is popular in LeetCode and GeeksForGeeks. A collection of hundreds of interview questions and solutions are available in our blog at Interview Question

Solution

No comments:

Post a Comment