Tesla interview question

Coding challenge in a codepad