Back to problems

In-place unique prefix

Algorithm · Meta · Medium

You are handed an array of integers nums whose entries are arranged in non-decreasing order, meaning each element is greater than or equal to the element directly before it. Rewrite nums in place so that every distinct value occupies exactly one slot inside a leading block of the array, and those distinct values keep the same relative order in which they originally appeared. Return the size of that leading block. More precisely, if the number you return is $$k$$, then once…

Checking your access…