N26 interview question

Medium level DP problem - hills and valleys