Tesla interview question

Leetcode like question about algorithms