MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / getNthFib

Function getNthFib

recursion/fibonacci-nth.js:3–7  ·  view source on GitHub ↗
(n, dic = { 1: 0, 2: 1 })

Source from the content-addressed store, hash-verified

1// time O(n)
2// space O(n)
3function getNthFib(n, dic = { 1: 0, 2: 1 }) {
4 if (n in dic) return dic[n];
5 dic[n] = getNthFib(n - 1, dic) + getNthFib(n - 2, dic);
6 return dic[n];
7}
8
9// time O(n)
10// space O(1)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected