Implement matrix multiplication and fast exponentiation
Company: WeRide
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates competency in matrix multiplication, modular arithmetic, and exponentiation algorithms as applied to large-scale numeric computations such as sequence generation.
Matrix Multiplication
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([[1,2],[3,4]], [[5,6],[7,8]], None)
Expected Output: [[19, 22], [43, 50]]
Explanation: Basic matrix multiplication.
Input: ([[2]], [[5]], 7)
Expected Output: [[3]]
Explanation: Modulo is applied if provided.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.
Exponentiation By Squaring
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (2,10,None)
Expected Output: 1024
Explanation: 2^10.
Input: (2,10,1000)
Expected Output: 24
Explanation: Modulo exponentiation.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.
Fast Fibonacci With Matrix Power
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: (10,None)
Expected Output: 55
Explanation: F(10)=55.
Input: (100,1000)
Expected Output: 75
Explanation: Modulo Fibonacci.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.