Given an n-dimensional array filled with numbers, output which p-dimensional array has the largest sum.
- An n-dimensional array of numbers, or your language's equivalent. You can assume this is a rectangular array, or not.
- n, the number of dimensions in the array. (doesn't need to be called
- p, the number of dimensions in the arrays you are adding up. (doesn't need to be called
The respective indices of the p-dimensional array with the largest sum. You may have undefined behavior in the case of a tie. The dimensions of the array that you find should be the last p dimensions of the original array.
[[[4,2], [6,8]], [[0,0], [500,327]]], 3, 2
[[1,2], [4,3]], 2, 0
Since p=0, you're just finding the largest number in the array, which in this case is 4. The coordinates are:
[[1,2], [4,-1]], 2, 1
You might see the 1 and 4 in the same column, and that that would have the largest sum of 5. However, because those share the second index, not the first, they are ignored. Both of the rows in this array add to 3, resulting in a tie, so you can return whatever you want here.
[[1,2], [3,4]], 2, 2
Since p=n, there are no indices of the array with the largest sum, so the output would be empty.