Fast Power and Modular Power
Asked at Meta · Coding Questions · Difficulty: Medium
Raising a number to a large power by multiplying it by itself `n` times is far too slow when `n` is in the billions. Implement exponentiation that needs only a logarithmic number of multiplications, first for a real base with a possibly negative exponent, then for integers modulo `p`.
Loading the problem…
More Meta interview questions
- LLM conceptual questions
- Implement a Two-Hidden-Layer MLP with Backpropagation in NumPy
- Dot Product with Run-Length Encoded Vectors
- Count Lakes Wrapped by a Given Island
- Minimum Remove to Make Valid Parentheses
- LLM with Beam Search and Nucleus Sampling (Meta MSL)