Google Interview Question

dp plus graph approach qsn