Either select the best sum till previous_index or select the current element + best_sum till index - 3
dp [ i ] = max ( dp [ i - 1 ] , a [ i ] + dp [ i - 3 ] ) ; NEW_LINE i += 1 ; NEW_LINE return dp [ n - 1 ] ; NEW_LINE