Enphase Energy interview question

DSA Question on DYnamic Programming