
Find Non-Duplicate Number Instances (easy)
Problem Statement
Given an array of numbers sorted in non-decreasing order, remove the duplicates in place so that each distinct value appears only once, keeping the values in sorted order at the front of the array. You may not use any extra space, so the solution must use constant extra space, O(1).
Return k, the number of distinct values. What the array holds beyond the first k positions does not matter and is not checked.
Example 1:
Input: [2, 3, 3, 3, 6, 9, 9]
Output: 4
Explanation: There are four distinct values, so the first four elements become [2, 3, 6, 9]. Whatever sits beyond position 4 is ignored.
Example 2:
Input: [2, 2, 2, 11]
Output: 2
Explanation: There are two distinct values, so the first two elements become [2, 11]. Whatever sits beyond position 2 is ignored.
Constraints:
- 1 <= nums.length <= 3 * 10<sup>4</sup>
-100 <= nums[i] <= 100numsis sorted in non-decreasing order.
Try it yourself
Try solving this question here:
Python3
Python3
Mark as Completed
No code editor for this lesson
This lesson focuses on concepts and theory