Pergunta de entrevista da empresa Booking.com

HackerRank test, Leetcode easy/medium difficulty.