Tech Mahindra interview question

dp related problems, array related for problems