Visa Inc. Interview Question

Better solution than dynamic programming?