# Fibonacci Numbers — coding interview question

Aced (formerly Exponent) publishes a public search API over its indexed pages; the guide is at https://www.aced.io/agents/agent-access.

Source: https://www.aced.io/questions/3631/fibonacci
Source observed: 2026-11-05T00:17:12.974Z
Last checked: 2026-11-05T00:17:12.974+00:00
Indexed: 2026-11-07T03:42:45.266+00:00

---

# Fibonacci Numbers

**Difficulty:** Easy  
**Category:** [Data Structures & Algorithms](https://www.aced.io/questions?type=algorithms) and [Coding](https://www.aced.io/questions?type=coding)  
**Related role:** [Software Engineer](https://www.aced.io/questions?role=swe)  
**Other associated role:** [Data Scientist](https://www.aced.io/questions?role=data-science)

We provide this coding-practice question through Aced, formerly Exponent. It asks you to implement `fib(n)` and return the nth Fibonacci number.

## Problem

Write a function `fib(n)` that returns the *nth* Fibonacci number. We define the sequence as:

- `F(n) = F(n-1) + F(n-2)`
- `F(0) = 1`
- `F(1) = 1`

This produces the sequence:

```text
1, 1, 2, 3, 5, 8, 13, ...
```

### Examples

```python
fib(0)  # => 1
fib(1)  # => 1
fib(2)  # => 2
fib(3)  # => 3
...
fib(10) # => 89
fib(20) # => 10946
```

The question interface includes **Question**, **Solution**, and **Community** tabs. It also provides expandable **Hint 1**, **Hint 2**, **Hint 3**, and **Challenge 1** sections. No community answers had been contributed in the supplied content.

To run code in the editor, [sign up](https://www.aced.io/signup?src=lesson). The interface includes Editor and Share views, plus Output, Test Results, and Console panels.

## Interview metadata

The supplied interface shows **33** community items in the question area and a control for **26 interviews**. It identifies the question as having been reported last asked **10 months ago** at the observation timestamp supplied for this document.

Associated company filters are [Bloomberg](https://www.aced.io/questions?company=bloomberg), [Cognizant](https://www.aced.io/questions?company=cognizant), [Oracle](https://www.aced.io/questions?company=oracle), [Adobe](https://www.aced.io/questions?company=adobe), and [Google](https://www.aced.io/questions?company=google).

## Interview experiences

We include three shared interview experiences related to this question:

1. [Bloomberg interview experience](https://www.aced.io/experiences/bloomberg-software-engineer-interview-4236da) — Bloomberg, **10 months ago**, Software Engineer, Entry Level / L3: “Long process and no direct interactions with recruiter. Rejected despite solving R2 in several different ways.”
2. [Cognizant interview experience](https://www.aced.io/experiences/cognizant-software-engineer-interview-fb7044) — Cognizant, **a year ago**, Software Engineer, Entry Level / L3: “The Process was easy, even though I am in my final year of B.Tech. I would say basics from multiple domains or tech stacks are enough to get into Cognizant for freshers.”
3. [Google interview experience](https://www.aced.io/experiences/google-software-engineer-interview-2739ac) — Google, **3 years ago**, Software Engineer, Mid Level / L4: “They give you a study guide. I'd recommend reading it. It's your classic data structure and algorithms interviews.”

## Related practice

### Related questions

- [Number Finder](https://www.aced.io/questions/3627/number-finder)
- [Find Largest Numbers](https://www.aced.io/questions/3623/find-largest-numbers)

### Related courses

![Data Science Interview Prep](https://images.ctfassets.net/x78yjrjc11pq/3U4C5C0OkDR0UeGch4AmlE/7ad489430b676a088cb973307fe77884/Data_Science_Interview_Prep_Course.jpeg?w=800&h=800&fm=webp&q=75)

#### [Data Science Interview Prep](https://www.aced.io/courses/data-science)

We cover mock interviews, frameworks, and advice from senior candidates, with practice in statistics, experimentation, coding, SQL, machine learning, and behavioral interviews. The course is positioned for people targeting data science roles at Google, Amazon, Microsoft, Meta, Apple, and other companies.

![SQL Interviews](https://images.ctfassets.net/x78yjrjc11pq/62mN54S54HpLIOmyG8qbnq/54deaf5e397d0807d71c0e27e21e5ee3/sql_illustration_2.jpg?w=800&h=800&fm=webp&q=75)

#### [SQL Interviews](https://www.aced.io/courses/sql-interviews)

We help candidates prepare for SQL interviews through syntax basics, aggregations, window functions, data manipulation, complex queries, and analysis of diverse datasets.

## Other Aced resources

We provide interview preparation through courses and practice areas including:

- [Product Management](https://www.aced.io/courses/pm?src=nav) — strategy cases to technical skills.
- [Forward Deployed](https://www.aced.io/courses/forward-deployed-engineering?src=nav) — beta preparation for FDE loops at Anthropic, OpenAI, Palantir, and more.
- [Engineering Management](https://www.aced.io/courses/engineering-management?src=nav) — leadership and people-management skills.
- [Software Engineering](https://www.aced.io/courses/software-engineering?src=nav) — strategies for coding problems.
- [System Design](https://www.aced.io/courses/system-design-interviews?src=nav) — architectures, interfaces, and databases under time pressure.
- [Data Science](https://www.aced.io/courses/data-science?src=nav) — statistical techniques and experimentation.
- [Machine Learning](https://www.aced.io/courses/ml-engineer?src=nav) — building, evaluating, and deploying AI/ML models.
- [Data Engineering](https://www.aced.io/courses/data-engineering?src=nav) — data models and ETL pipelines.
- [AI Engineering](https://www.aced.io/courses/ai-engineering?src=nav)
- [Investment Banking](https://www.aced.io/ib?src=nav)
- [Generative AI](https://www.aced.io/courses/gen-ai-interviews?src=nav)
- [Security Engineer](https://www.aced.io/courses/security-engineer?src=nav)
- [TPM](https://www.aced.io/courses/tpm?src=nav)
- [Solutions Architect](https://www.aced.io/courses/solution-architect-interview?src=nav)
- [UX / Product Design](https://www.aced.io/courses/product-designer-interview?src=nav)
- [BizOps & Strategy](https://www.aced.io/courses/bizops?src=nav)

We also provide [Loops](https://www.aced.io/guides?src=nav), [Experiences](https://www.aced.io/experiences?src=nav), [Practice](https://www.aced.io/practice?src=nav), [coaching](https://www.aced.io/coaching?src=nav), [pricing and upgrades](https://www.aced.io/upgrade?src=questions), [job referrals](https://www.aced.io/jobs/referrals?src=nav), [resources](https://www.aced.io/resources?src=nav), and [sign-up](https://www.aced.io/signup?src=nav).

---

[Read this page’s summary](https://www.aced.io/agents/api/public/v1/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3631%2Ffibonacci&trace=t_679ff9ab98f3)

## Ask a follow-up about this page

Need a more specific answer? Ask the exact question you have. It returns a fresh, cited answer from Aced (formerly Exponent)’s knowledge base. No account or API key required.

Open this URL with your own question, URL-encoded. Include your question in q. All research inputs are optional; no account or setup.

`GET https://www.aced.io/agents/agent/faq?q={question}&trace=t_679ff9ab98f3`

[Tool guide and examples](https://www.aced.io/agents/agent-access) · [OpenAPI](https://www.aced.io/agents/api/public/v1/openapi.json) · [Page TLDR form](https://www.aced.io/agents/agent-tools/page-tldr?url=https%3A%2F%2Fwww.aced.io%2Fquestions%2F3631%2Ffibonacci). Opening a form does not execute a tool.