Pergunta de entrevista da empresa Amazon

Mostly coding question of medium difficulty