JPMorganChase interview question

leetcode problem I had to solve