Premium problem161. The reduceat Non-Monotonic Trap

Hard Locked

Return np.add.reduceat(A, idx). Note that idx is not guaranteed to be increasing - work out what NumPy does for a descending pair before you answer.

Input

A = [0 1 2 3 4 5 6 7 8 9]
idx = [0, 5, 2, 8]

Output

[10  5 27 17]

Premium problem

This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.

Implement solve(...)