Showing:
Handle Score
@Ibrahim Nash 5765
@akhayrutdinov 5111
@mb1973 4993
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
Largest zigzag sequence
Easy Accuracy: 25.71% Submissions: 35 Points: 2

Given a matrix M of size n * n, the task is to find sum of the zigzag sequence with the largest sum. A zigzag sequence starts from the top and ends at the bottom. Two consecutive elements of sequence cannot belong to same column.

Example 1:

Input: n = 3
M = {{3, 1, 2},
{4, 8, 5},
{6, 9, 7}}
Output: 18
Explaination: The sequence is (3, 8, 7).

Example 2:

Input: n = 3
M = {{1, 2, 4},
{3, 9, 6},
{11, 3, 15}}
Output: 28
Explaination: The sequence is 4, 9, 15.

You do not need to read input or print anything. Your task is to complete the function zigzagSequence() which takes n and M as input parameters and returns the highest zigzag sum.

Expected Time Complexity: O(n3)
Expected Auxiliary Space: O(n2)

Constraints:
1 ≤ n ≤ 100
1 ≤ M[i][j] ≤ 1000