Domanda di colloquio di JPMorganChase

Coding question on hacker rank, probably Leetcode easy to medium