Meta interview question

array traversal q - leetcode medium