Pergunta de entrevista da empresa Wingify

he asked me one puzzle question, one DP problem,