@ilyakava Coded up dynamic programming solution for fun

Just couldn't resist...