tvl-depot/scratch/deepmind/part_two
William Carroll 8d36c6d00f Solve InterviewCake's compute nth Fibonacci
While the "Dynamic programming and recursion" section hosts this problem, the
optimal solution does not use recursion. Many cite the Fibonacci problem as a
quintessential dynamic programming question. I assume these people expect an
answer like:

```python
def fib(n):
  cache = {0: 0, 1: 1}
  def do_fib(n):
    if n in cache:
      return cache[n]
    else:
      cache[n - 1] = do_fib(n - 1)
      cache[n - 2] = do_fib(n - 2)
      return cache[n - 1] + cache[n - 2]
  return do_fib(n)
```

The cache turns the runtime of the classic Fibonacci solution...

```python
def fib(n):
  if n in {0, 1}:
    return n
  return fib(n - 1) + fib(n - 2)
```

... from O(2^n) to a O(n). But both the cache itself and the additional stacks
that the runtime allocates for each recursive call create an O(n) space
complexity.

InterviewCake wants the answer to be solved in O(n) time with O(1)
space. To achieve this, instead of solving fib(n) from the top-down, we solve it
from the bottom-up.

I found this problem to be satisfying to solve.
2020-03-30 14:14:02 +01:00
..
misc Tidy up structure of briefcase 2020-02-12 16:58:29 +00:00
.envrc Drop support for lorri 2020-03-27 10:59:50 +00:00
balanced-binary-tree.py Solve InterviewCake's balanced-binary-tree problem 2020-03-14 12:48:37 +00:00
bst-checker.py Solve InterviewCake's bst-checker problem 2020-03-15 23:09:29 +00:00
cafe-order-checker.py Solve InterviewCake's cafe-order-checker problem 2020-02-20 15:20:58 +00:00
delete-node.py Tidy up structure of briefcase 2020-02-12 16:58:29 +00:00
dir-locals.nix Drop support for lorri 2020-03-27 10:59:50 +00:00
find-duplicate-optimize-for-space-beast-mode.py Solve InterviewCake's find duplicate beast mode 2020-03-26 11:55:06 +00:00
find-duplicate-optimize-for-space.ts WIP: Partially solve InterviewCake's find duplicate number 2020-03-10 15:01:30 +00:00
find-rotation-point.ts Solve InterviewCake's "find rotation point" problem 2020-03-10 13:27:11 +00:00
graph-coloring.ts Solve InterviewCake's graph-coloring problem 2020-03-19 12:31:24 +00:00
highest-product-of-3.py Solve InterviewCake's highest-product-of-3 2020-03-01 22:32:25 +00:00
inflight-entertainment.ts Solve InterviewCake's inflight-entertainment problem 2020-02-21 11:30:01 +00:00
merge-sorted-arrays.ts Solve InterviewCake's merge sorted arrays question 2020-02-19 16:02:38 +00:00
merging-ranges.py Solve merging-ranges 2020-02-13 14:52:20 +00:00
mesh-message.py Solve InterviewCake.com's mesh-message problem 2020-03-20 16:49:49 +00:00
nth-fibonacci.py Solve InterviewCake's compute nth Fibonacci 2020-03-30 14:14:02 +01:00
package-lock.json Run Prettier across projects 2020-03-27 10:59:50 +00:00
package.json Run Prettier across projects 2020-03-27 10:59:50 +00:00
permutation-palindrome.py Solve InterviewCake permutation-palindrome problem 2020-03-01 22:32:24 +00:00
product-of-other-numbers.py Solve InterviewCake's product-of-other-numbers 2020-03-02 16:45:15 +00:00
recursive-string-permutations.ts Solve InterviewCake's recursive string permutations problem 2020-03-26 19:43:40 +00:00
reverse-string-in-place.ts Tidy up structure of briefcase 2020-02-12 16:58:29 +00:00
reverse-words.py Solve bonus part of reverse-words 2020-02-19 15:01:42 +00:00
second-largest-item-in-bst.ts Solve InterviewCake's second-largest-item-in-bst 2020-03-16 11:45:34 +00:00
shell.nix Drop support for lorri 2020-03-27 10:59:50 +00:00
shuffle.py Implement an in-place shuffling algorithm 2020-03-06 18:45:55 +00:00
stock-price.py Solve InterviewCake's stock-price problem 2020-03-01 22:32:25 +00:00
todo.org Solve InterviewCake's compute nth Fibonacci 2020-03-30 14:14:02 +01:00
top-scores.py Solve InterviewCake's top-scores 2020-03-01 22:32:24 +00:00
top-scores.ts Run Prettier across projects 2020-03-27 10:59:50 +00:00
tsconfig.json Solve InterviewCake's graph-coloring problem 2020-03-19 12:31:24 +00:00
word-cloud.py Solve InterviewCake's word-cloud problem 2020-03-01 22:32:24 +00:00