Google Interview Question

Focus on two pointers, graphs, and dp