Pergunta de entrevista da empresa Amazon Robotics

One question in leetcode, mid level difficulty