Given a 1-D int array groups, already sorted so equal values are contiguous, return an int array of positions within each group:
groups
ROW_NUMBER() OVER (PARTITION BY group)
Input
[1 1 1 2 5 5]
Output
[0 1 2 0 0 1]
This one's part of Premium. Unlock the full NumPy track plus every other premium problem on the site.
solve(...)