Super Pow

Solution Code
class Solution:
    def superPow(self, a: int, b: list[int]) -> int:
        if not b:
            return 1
        last_digit = b.pop()
        
        part1 = pow(self.superPow(a, b), 10, 1337)
        part2 = pow(a, last_digit, 1337)
        
        return (part1 * part2) % 1337
Video GuideLeetcode Daily

Time Complexity

O(N)

Space Complexity

O(1)