### Remove Duplicates from Sorted Array (Main Thread)

Here is the interview question prompt, presented for reference.

Given a non-decreasing sorted array of integers num, we have eliminated all the duplicated elements so that each element should be unique in the array. The relative arrangement of the elements must remain unchanged.

Let's take an example of a sorted integer array `num = [1, 2, 3, 3, 4, 4, 5, 6, 6, 6, 8, 8]`. Our function will return the length of the array = 8, and the resultant output of the given array after removing the duplicate element will `result = [1, 2, 3, 4, 5, 6, 8]`.

![Remove Duplicate Elements from the array](https://storage.googleapis.com/algodailyrandomassets/curriculum/remove-duplicates-from-sorted-array/image1.png)

Let's take another example of a sorted integer array `num = [1, 2, 2, 3, 4, 4, 4, 5, 5]`. Our function will return the length of the array = 5, and the resultant output of the given array after removing the duplicate element will be the `result = [1, 2, 3, 4, 5]`.

![Remove Duplicate Elements from the array](https://storage.googleapis.com/algodailyrandomassets/curriculum/remove-duplicates-from-sorted-array/image2.png)

# Prompt:

Given a sorted array, develop a program to eliminate duplicate elements to ensure that there is only a single instance of each element. - We have to return the length of the array and the resultant array containing a single instance of each element present in the array.

# Constraints:

• An array, `num`, is sorted in non-decreasing order.
• length of `num > 0`

You can see the full challenge with visuals at this link.

Challenges • Asked 6 months ago by Jake from AlgoDaily

Jake from AlgoDaily Commented on Sep 10, 2022:

This is the main discussion thread generated for Remove Duplicates from Sorted Array (Main Thread).