Skip to the code
+50 XP

#642 Power Tower Checksum

hard

A file-integrity tool computes a checksum a^b mod 1337, where b is so large that it's stored as an array of its decimal digits, digits, most significant first (for example [1, 0] means 10).

Write towerChecksum(a, digits) that returns a^b mod 1337. b is at least 1.

Example 1

Input: a = 2, digits = [3]
Output: 8

2^3 = 8.

Example 2

Input: a = 2, digits = [1,0]
Output: 1024

b is 10, and 2^10 = 1024, which is less than 1337.

Constraints

  • 0 <= a <= 2^31 - 1
  • 1 <= digits.length <= 10^5
  • 0 <= digits[i] <= 9, digits has no leading zeros, and b >= 1.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).