Tesla interview question

Python DP question, not too bad