2-Sigma interview question

dynamic programming and code in python