Nextlabs interview question

Leetcode style question to probe own thinking process