Frage im Vorstellungsgespräch bei Tesla

Leetcode "hard" programming question, dynamic programming related.