Tesla Interview Question

medium to hard LC question