Largest Deep Sum
Wolfram Language (Mathematica), 36 bytes
#~Position~Max@#&@Total[#,{-#2,-1}]&
Try it online!
Returns an array containing all the indices where the maximum value can be found. So for normal inputs that's a singleton array, containing the list of indices to it. If there's a tie, you'll get all the lists of indices for where that value shows up.
The function doesn't actually read the n
parameter, because it isn't needed, but you could pass it in as a third argument if you like (it would just be ignored anyway).
One catch here is that for some reason the dimension specification {0,-1}
for Total
never sums anything. I don't really understand why, but luckily that's just what we need for this challenge.
APL (Dyalog), 21 bytes
(⍴⊤⊃∘⍒∘,)+/,⍤⎕⊢⎕
First input is the array, second is p
.
Try it online!
How?
+/,⍤⎕
- apply sum over sub arrays of rank p
⊃∘⍒∘,
- flatten, grade down and take first
⍴⊤
- encode in the mixed base derived by the shape of the previous result