Commit graph

2 commits

Author SHA1 Message Date
William Carroll
9549dbb266 Update BFS impls
I've subtly been implementing breadth-first traversals in graphs
incorrectly. The change is subtle, but updating `seen` needs to happen
immediately after queuing an item.

The results will remain the same, but the runtimes will differ dramatically. I
didn't notice this until I attempted to complete LeetCode's "count islands"
challenge, and LeetCode rejected my solution because it could not finish before
timing out. After looking at other candidates' solutions and comparing them to
mine, I couldn't see any difference... except for this subtle difference.

This SO answer provides a helpful explanation:
https://stackoverflow.com/questions/45623722/marking-node-as-visited-on-bfs-when-dequeuing

The take-away lesson here is to always call `seen.add(..)` immediately after
enqueuing.
2020-11-23 23:21:20 +00:00
William Carroll
aa66d9b83d Add coding exercises for Facebook interviews
Add attempts at solving coding problems to Briefcase.
2020-11-12 14:37:29 +00:00