Pergunta de entrevista da empresa Forward

LC-like 2D array traversal/manipulation question