Epic Games interview question

Basic dynamic programming question, string question