Code Challenge #11: June 21, 2017
Every week, we feature the type of brain-teasing question that might be asked in a full-stack developer’s job interview at places such as Google and Facebook.
This week’s challenge is a very common interview question and was reported to have been asked in interviews at many top companies including Google:
Write a function,
fibonacciFinder50, that will find the 50th number in the Fibonacci Sequence.
- Input: There are no parameters to this function
- Output: an integer, the 50th number in the Fibonacci Sequence
fibonacciFinder50() => 7778742049
- In the Fibonacci Sequence, the first two numbers are
1and every number thereafter is the sum of the previous two numbers in the sequence
- For this challenge, consider
0to be the
1stFibonacci Number, not the
0th(i.e. do not zero-index)
Find out more about basic challenges.
Write a function,
fibonacciFinderN, that will find the
nth number in the Fibonacci Sequence.
Input: any integer,
nis a natural number (in this case not including 0)
Output: an integer, the
nth number in the Fibonacci Series
fibonacciFinderN(300) => 137347080577163115432025771710279131845700275212767467264610201
- Please use this example – the 300th Fibonacci Number – with your submission
Find out more about intermediate challenges.
fibonacciFinderNas efficiently as possible.
- Can you solve this challenge in
- Many of you will still find that this challenge is too easy (and this is not unusual), so see how you can stretch yourself further. Can you solve this problem in an unorthodox or elegant way? How about in a different language? Take this opportunity to show off your scripting skills and creative outside-the-box thinking!
Reply to this thread with a link to your code on repl.it and paste your properly formatted code to participate! Don’t just submit your code, remember to
explain your solution, too! If you want to be considered as the winner, your function
must have the
correct name and provide
output in the format specified above, you also need to abide by our other simple rules.
As always solutions using imports to do all the heavy lifting such as
itertools will not be considered for the winner.
The fine print:
Click the links to find out more about:
- the rules & how to participate in challenges
- how challenges are used as job interview questions
- why Codecademy runs challenges (and why they are formatted this way)
- more details about the challenges and why we think they are useful.
- find previous challenges (and see the past winners) in our Challenge Index