This question is from TekSystem coding round 2. I tried with normal Dp approach but got runtime error due to large constraint.