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.
Brief explanation it checks both the row and column count since there could be more than 6 in either, added guards just in case. For the maxHourglassRow and maxHourglassCol I remove the first and last position a long side with one more for indexing giving to a total of 3 hence the maxHourglassRow - 3 (The exercise has 6 numbers, so if I remove 3, I am left with 3 indexing starts with 0 and I want to start counting to sum them i.e. row[0][0], row[0][1], row[0][2] <- the 0, 1 , 2 represent a column in a 2 dimensional array). In the sum I reused a method to sum the 3 columns from the top of the hourglass and the bottom as well, any comment is welcomed. I believe there could be improvements but for now this is what I came up with.
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
C# SOLUTION
Brief explanation it checks both the row and column count since there could be more than 6 in either, added guards just in case. For the maxHourglassRow and maxHourglassCol I remove the first and last position a long side with one more for indexing giving to a total of 3 hence the maxHourglassRow - 3 (The exercise has 6 numbers, so if I remove 3, I am left with 3 indexing starts with 0 and I want to start counting to sum them i.e. row[0][0], row[0][1], row[0][2] <- the 0, 1 , 2 represent a column in a 2 dimensional array). In the sum I reused a method to sum the 3 columns from the top of the hourglass and the bottom as well, any comment is welcomed. I believe there could be improvements but for now this is what I came up with.