Pregunta de entrevista de Amazon

Leetcode hard question, about different algorithms