Pregunta de entrevista de Pinwheel (NY)

Practical coding question in the range of LC medium difficulty