Either select the best sum till previous_index or select the current element + best_sum till index - k
while ( i < n ) { dp [ i ] = maxi ( dp [ i - 1 ] , arr [ i ] + dp [ i - k ] ) ; i ++ ; } return dp [ n - 1 ] ; }