Algorithm · Weride · Medium
Problem Write a function that computes base raised to the power of exp (i.e., base exp ) using an efficient algorithm. Requirements The time complexity must be O(log exp). Use only ordinary multiplication (no built-in power functions). Function Signature Examples Example 1 Explanation: 2 10 equals 1024. Example 2 Explanation: 3 5 = 3 * 3 * 3 * 3 * 3 = 243. Example 3 Explanation: Any non-zero number raised to the power 0 is 1. Constraints exp is a non-negative integer. base…
Checking your access…