Implement the method fibonacci that returns the nth Fibonacci number.
Return the Fibonacci number at position n. The sequence starts with F(0) = 0 and F(1) = 1.
The task is designed to test careful handling of edge cases, not only the most common input.
- Return
0forn = 0. - Return
1forn = 1. - An iterative solution avoids repeated recursive work.
Keep the previous two sequence values and update them until the requested position is reached.