Tesla Interview Question

Coding challenge in a codepad