Visa Inc. interview question

Better solution than dynamic programming?