Tesla Interview Question

Very easy algorithm question and react question.