refactor greatest_sum method to use recursion