Segantii interview question

Pair programming. Questions from Leetcode