values of length n. For each index i, cut the array right after it: the left part holds the elements at indices 0 through i, and the right part holds everything after i (it may be empty).
Count how many **distinct** values the left part has and subtract the number of distinct values in the right part.
Return an array of these n differences, one per index i.values=[4, 4, 7, 1] → [-2, -1, 1, 3]
At index 0 the left part {4} has one value and the right part {4, 7, 1} has three, so 1 − 3 = −2. At index 1 the left is still {4} and the right is {7, 1}: 1 − 2 = −1. Then 2 − 1 = 1 and 3 − 0 = 3.
values=[9] → [1]
One value on the left, nothing on the right: 1 − 0 = 1.
values=[2, 5, 2, 5, 2] → [-1, 0, 0, 1, 2]
values=[4, 4, 7, 1]
[-2, -1, 1, 3]
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.