Commit graph

7 commits

Author SHA1 Message Date
William Carroll
c00eed469c Solve "cafe order checker" (again)
Perhaps my fifth iteration of solving this problem.
2020-11-21 16:31:53 +00:00
William Carroll
6ccdb06717 Solve "permutation palindrome" (again)
Python's `collections` library really shines for this problem.
2020-11-21 16:24:14 +00:00
William Carroll
60d7ea5b91 Implement a queue using two stacks
The space cost is O(n). The runtime cost of enqueue is O(1); the runtime cost of
dequeue is O(n). Using the "accounting method", the cost of an item in the
system is O(1). Here's why:

+------------+----------------------------+------+
| enqueue    | push onto lhs              | O(1) |
+------------+----------------------------+------+
| lhs -> rhs | pop off lhs; push onto rhs | O(1) |
+------------+----------------------------+------+
| dequeue    | pop off rhs                | O(1) |
+------------+----------------------------+------+
2020-11-21 16:15:43 +00:00
William Carroll
417d3b5fff Implement a bottom-up fibonacci
The bottom-up solution run in O(n) time instead of O(2^n) time, which the
recursive solution runs as:

```
def fib(n):
    return fib(n - 2) + fib(n - 1)
```

Remember that exponential algorithms are usually recursive algorithms with
multiple sibling calls to itself.
2020-11-21 14:48:12 +00:00
William Carroll
70e74a4027 Solve "linked-list-cycles"
Write a predicate for checking if a linked-list contains a cycle. For additional
practice, I also implemented a function that accepts a linked-list containing a
cycle and returns the first element of that cycle.
2020-11-21 14:47:18 +00:00
William Carroll
cbdac30643 Reimplement bst-checker
Practice makes perfect. See the previous commit for a more details about this
solution.
2020-11-21 14:21:05 +00:00
William Carroll
1dc6695a47 Solve merge-sorted-arrays (again)
InterviewCake.com has a section on Facebook's interview, so I'm attempting to
solve all of the problems on there even if that means I'm resolving
problems. The more practice, the better. Right?

URL: interviewcake.com/facebook-interview-questions
2020-11-21 13:41:33 +00:00