Pergunta de entrevista da empresa Trilogy

Coding rounds, DS based algo question