Compute the start offsets of variable-length sequences when they are concatenated end to end (a 'packed' batch): the exclusive cumulative sum of the lengths. Lengths must be non-negative.
Implement solve(lengths).
Returns. Return an integer NumPy array with one offset per sequence (empty input gives an empty array); a negative length raises ValueError.
Example 1
Input:
solve([3, 1, 2])
Output:
[0, 3, 4]
Example 2
Input:
solve([0, 4, 0, 2])
Output:
[0, 0, 4, 4]
No results yet
Run your code to check it against the examples, or submit to run every test.