Reduce a Power Given Decimal Exponent Digits

Quick Overview

Practice evaluating a modular power whose positive exponent is supplied as decimal digits. Handle long exponents, place value, and all permitted bases safely.

Reduce a Power Given Decimal Exponent Digits

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

# Reduce a Power Given Decimal Exponent Digits Given a positive integer `a` and a list `b` containing the decimal digits of a positive exponent, return `a` raised to that exponent, modulo `1337`. The exponent may contain up to `2000` digits. ### Function `int superPow(int a, vector<int>& b)` ### Example 1 ```text Input: a = 3, b = [4] Output: 81 ``` ### Example 2 ```text Input: a = 2, b = [1,1] Output: 711 ``` The exponent is `11`. The remainder of `2048` divided by `1337` is `711`. ### Example 3 ```text Input: a = 1337, b = [2] Output: 0 ``` ### Constraints - `1 <= a <= 2147483647`. - `1 <= b.length <= 2000`. - `0 <= b[i] <= 9`. - `b` has no leading zero and represents a positive integer. ### Clarifications The digits are supplied most significant first. Return a remainder in the range `0` through `1336`; do not return the full power. No assumption that `a` is relatively prime to `1337` is given. ### What a Strong Answer Covers - Correct interpretation of the exponent digits. - Handling an exponent too large for ordinary integer types. - Correct remainders for all allowed bases. - A correctness argument and numeric/time/storage bounds.

Overview: Practice evaluating a modular power whose positive exponent is supplied as decimal digits. Handle long exponents, place value, and all permitted bases safely.

Google logo
Google
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Reduce a Power Given Decimal Exponent Digits

Given a positive integer a and a list b containing the decimal digits of a positive exponent, return a raised to that exponent, modulo 1337.

The exponent may contain up to 2000 digits.

Function

int superPow(int a, vector<int>& b)

Example 1

Input: a = 3, b = [4]
Output: 81

Example 2

Input: a = 2, b = [1,1]
Output: 711

The exponent is 11. The remainder of 2048 divided by 1337 is 711.

Example 3

Input: a = 1337, b = [2]
Output: 0

Constraints

  • 1 <= a <= 2147483647 .
  • 1 <= b.length <= 2000 .
  • 0 <= b[i] <= 9 .
  • b has no leading zero and represents a positive integer.

Clarifications

The digits are supplied most significant first. Return a remainder in the range 0 through 1336; do not return the full power. No assumption that a is relatively prime to 1337 is given.

What a Strong Answer Covers Guidance

  • Correct interpretation of the exponent digits.
  • Handling an exponent too large for ordinary integer types.
  • Correct remainders for all allowed bases.
  • A correctness argument and numeric/time/storage bounds.