Dynamic Programming for Competitions and Interviews