Amazon Interview Question

DP on graphs and monotnic stack