nums in non-decreasing order.ans to 0, which will hold the total number of operations.up to 0, which will count the number of unique elements encountered so far.up.up to ans for each element in the array.ans as the total number of operations.