Premium problem147. Number the Rows Within Each Group

Medium Locked

Given a 1-D int array groups, already sorted so equal values are contiguous, return an int array of positions within each group:

  • each element gets its 0-based position within its own group
  • this is ROW_NUMBER() OVER (PARTITION BY group)

Input

[1 1 1 2 5 5]

Output

[0 1 2 0 0 1]

Premium problem

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

Implement solve(...)