about | help | code help+videos | done | prefs |
Write a method that accepts a 1-dimensional array of integers that represents a square, 2-dimensional array. The width and height of the 2-dimensional array will be "len". Your goal is to return the sum of all the elements in the array, except that all of the elements along the "main diagonal" of the array count triple. For example: 4, 6, 7 1, 2, 5 8, 3, 1 has a sum of (3*4)+6+7+1+(3*2)+5+8+3+(3*1) = 51. Note that all of the input parameter arrays will represent square arrays, so, for example, you could have arrays with 9 elements or 16 elements, but not any length in between those since they would not form square arrays. The size could be anything as long as it forms a square array. Remember that "len" is the length of the sides of the square array, not the length of the input array. The array will contain at least one integer and the sum will between negative max int and positive max int. Be careful! addGrid([14], 1) → 42 addGrid([1, 7, 4, -3, -4, 9, 6, 2, 5], 3) → 31 addGrid([5], 1) → 15 ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 290
Copyright Nick Parlante 2017 - privacy