Anonymous Interview Question

Dp question, solve in 3hrs