Tesla Interview Question

Some medium hard Leetcode question