Pregunta de entrevista de Amazon Robotics

One question in leetcode, mid level difficulty