Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

Maximum Direction in a Matrix

By tahmedge, ishtupeed · Limits 1s, 512 MB

The Great Researcher Mr. Bari will give you some chocolates from Singapore if you can solve the following problem.

You are given an n*n array. You have to find out in which direction the maximum sum of numbers is located. Is it through any row, or any column or one of the two diagonals?


First you will take an integer number n(1≤n≤100) as input. In the following n lines, you will take n numbers as input in each of the lines. The numbers will be in range [-100, 100].


Compute the value of maximum sum of numbers through any direction(row wise or column wise or diagonally).


1 2 3
4 5 6
7 8 9

In the sample, maximum sum of numbers is through the last row which is 24.



87% Solution Ratio

BruteforcekidEarliest, May '18

rogue_33Fastest, 0.0s

shoumoLightest, 131 kB

touhidurrrShortest, 201B


Login to submit

Toph uses cookies. By continuing you agree to our Cookie Policy.