Find the largest sum by considering all possible next elements in sequence .
zzs = 0 ; NEW_LINE for k in range ( n ) : NEW_LINE INDENT if ( k != j ) : NEW_LINE INDENT zzs = max ( zzs , largestZigZagSumRec ( mat , i + 1 , k , n ) ) ; NEW_LINE DEDENT DEDENT dp [ i ] [ j ] = ( zzs + mat [ i ] [ j ] ) ; NEW_LINE return ( dp [ i ] [ j ] ) ; NEW_LINE