Tesla Interview Question

Python DP question, not too bad