Meta interview question

Basic algorithm question, leetcode medium