Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Maximum Points
EASY
10 mins
8 upvotes
Matrices (2D Arrays)
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Matrices (2D Arrays)
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Linked List
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Maximum Points

Contributed by
Vishal R S
Easy
yellow-spark
0/40
Avg time to solve 10 mins
Success Rate 90 %
Share
8 upvotes

Problem Statement

You are playing a video game, which contains an N x N grid. You start on the top left cell of the grid, and are free to move anywhere through the grid, any number of times.

Each cell in the grid has some number of points that you can collect from it and you can collect points at most once from each cell. Furthermore, it is possible to collect points from a cell, if and only if the cell lies on one of the two diagonals of the grid. Print the maximum number of points you can collect, given the grid.

For example:

If the grid is:
1 2
3 4
We can collect points from all cells as each cell lies on a diagonal. So, the maximum points will be 1+2+3+4 = 10.
Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
3 
1 2 3
4 5 6
7 8 9
1
5
Sample Output 1
25
5
Explanation for Sample Input 1:
For test case 1:
    We can sum up all the elements that lie on the diagonals, namely 1+5+9+3+7 = 25.

For Test case 2:
    Since there is only one element, we can take it.    
Sample Input 2:
1
2
4 5
6 7
Sample Output 2:
22
Reset Code
Full screen
Auto
copy-code
Console