Reddit Interview Question

data structures and algo question that builds on diff parts