Code Room
CodingHard
Question
Return the n-th Fibonacci number modulo m, where F(0) = 0 and F(1) = 1, for n that can be very large (up to 10^18). Linear iteration is too slow, so use 2x2 matrix exponentiation of [[1,1],[1,0]] by fast (binary) exponentiation, taking every product modulo m. Return 0 when m == 1.
Implement
fib_mod(n: int, m: int) → intExamples
in
[10,1000]out55What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.