o4-mini-2025-04-16· OpenAI
LMArena Human Preference 140K
Solve fibinoci theory in python in o(n) complexity
- User
Solve fibinoci theory in python in o(n) complexity
- Assistant
Here’s a simple, O(n)-time, O(1)-space Python implementation of the nᵗʰ Fibonacci number using an iterative loop:
pythondef fib(n: int) -> int: """ Return the n-th Fibonacci number. F(0)=0, F(1)=1, and F(n)=F(n-1)+F(n-2) for n>=2. Time: O(n), Space: O(1) """ a, b = 0, 1 for _ in range(n): a, b = b, a + b return a # Example if __name__ == "__main__": for i in range(10): print(f"F({i}) = {fib(i)}")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.