Amazon Interview Question

Trees, graphs and dp, stack