Say the entire range is 0 to 5. You need to keep a history of values in some way to know which is unique. For example, array, the logic is...Each line is a new value and how it is processed or handled.
A = [ 0] first value, last unique is 0
A = [ 0,1 ] next, last unique 1
A = [ 0,1,2 ] next, last unique is 2
A = [ 0,1,2,3 ] next, last unique is 3
At this point they are all unique values right? So 0, then 1, then 2, then 3 are the result you want? As the last unique value, right?
With more values...
A = [ 0,1,2,3 ] next
A = [ 0,1,2,3,4 ] next
A = [ 0,1,2,3,4,5 ] next
A = [ 0,1,2,3,4,5,0 ] next
Now you start to narrow the unique value list? So the last unique value is 5?
So I would say the last unique value is always the last value added to the array, unless, there is already a match in the array? Also if you find a match, you need to remove that value from the array so it can become unique again...
A = [ 0,1,2,3,4,5,0 ] remove 0, A = [ 1,2,3,4,5 ] next, last unique is 5
A = [ 1,2,3,4,5,0 ] next, now unique last unique is 0
Have I stated the logic correctly? There are other ways to keep the history, but the above is one easy way to do it. You could also keep an array of counters and increment the count for each match in the stream of values, and the lowest count is always the last unique unique value. But I think the above example is easier to understand and validate.