We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Only read if you have attempted to solve the problem
The key to solving this problem is finding the relationship between the row and column index positions when iterating through the 2d array.
For the main diagonal, the row and column indices will always be equal.
For the secondary diagonal, the column index will decrease as each row increases. This relationship can be described as col_index = (arr.size() - row_index - 1).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Only read if you have attempted to solve the problem
The key to solving this problem is finding the relationship between the row and column index positions when iterating through the 2d array.
For the main diagonal, the row and column indices will always be equal.
For the secondary diagonal, the column index will decrease as each row increases. This relationship can be described as col_index = (arr.size() - row_index - 1).