As reported: Synopsys R&D Engineer Sr, round 1 (2024): remove duplicates from a sorted array.
Given an integer array nums sorted in non-decreasing order, remove the duplicates in place so that each distinct value appears once, keeping the order. Return k, the number of distinct values; the first k elements of nums must hold them. What is left beyond index k does not matter.
This is LeetCode 26 — Remove Duplicates from Sorted Array.
Example 1
nums = [1,1,2] -> k = 2, nums starts with [1,2]
Example 2
nums = [0,0,1,1,1,2,2,3,3,4] -> k = 5, nums starts with [0,1,2,3,4]
Constraints: 1 ≤ nums.length ≤ 3·10^4; -100 ≤ nums[i] ≤ 100; nums is sorted in non-decreasing order.
Code runner format: one line: nums as a JSON array. Implement removeDuplicates(nums), which changes nums in place and returns k; the harness prints the first k elements of nums.