Loading…
Loading…
Given a sorted array, remove duplicates in-place so each unique element appears once. Print the count of unique elements followed by the deduplicated prefix, space-separated.
Input: 0 0 1 1 1 2 2 3 3 4
Output: 5 0 1 2 3 4
A slow pointer tracks the last confirmed-unique position; a fast pointer scans ahead. Whenever a new distinct value is found, advance the slow pointer and write it there.
Input (stdin)
Output
Input (stdin)
Output
Sign in to track solved problems and earn XP.
No discussions yet
Be the first to start a conversation.