Quick Overview

This question evaluates a candidate's understanding of algorithmic problem-solving, recurrence relations, numeric computation, and performance analysis, including discussion of time and space complexity and handling of large inputs or integer overflow.

Compute Fibonacci Numbers

Company: Plymouth Rock Assurance Corporation

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Write a function that returns the `n`th Fibonacci number. Definitions and requirements: - Use zero-based indexing: `fib(0) = 0`, `fib(1) = 1`. - For `n >= 2`, `fib(n) = fib(n - 1) + fib(n - 2)`. - The input `n` is a non-negative integer. - Discuss the time and space complexity of your approach. - If relevant, explain how your implementation handles large `n` values or integer overflow.

Overview: This question evaluates a candidate's understanding of algorithmic problem-solving, recurrence relations, numeric computation, and performance analysis, including discussion of time and space complexity and handling of large inputs or integer overflow.

Return the nth Fibonacci number using zero-based indexing.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: (0,)

Expected Output: 0

Explanation: fib(0) is 0.

Input: (1,)

Expected Output: 1

Explanation: fib(1) is 1.

Hints

  1. Clarify edge cases before coding.
  2. Keep outputs deterministic when several valid answers exist.

Compute Fibonacci Number

mediumPlymouth Rock Assurance CorporationData Scientist

Return the nth Fibonacci number using zero-based indexing.

View full question (all parts)

Write a function that returns the nth Fibonacci number.

Definitions and requirements:

  • Use zero-based indexing: fib(0) = 0, fib(1) = 1.
  • For n >= 2, fib(n) = fib(n - 1) + fib(n - 2).
  • The input n is a non-negative integer.
  • Discuss the time and space complexity of your approach.
  • If relevant, explain how your implementation handles large n values or integer overflow.

Examples

Example 1
Input
(0,)
Output
0
Notes
fib(0) is 0.
Example 2
Input
(1,)
Output
1
Notes
fib(1) is 1.

Constraints

  • •Inputs are Python literals matching the function signature.
  • •Return a deterministic exact-match value.

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Sample call
solution(0)
Language
Case 1
Input
(0,)
Expected
0
Case 2
Input
(1,)
Expected
1

Browse More Questions