Pergunta de entrevista da empresa Meta

2 questions, first one iterative and second one dynamic programming