Collapse Repeated Readings
A temperature probe writes its readings into a singly linked list that is already sorted in non-decreasing order. The list is given to you as an array values, where values[0] is the head and each element points to the next.
Whenever several neighbouring nodes hold the same reading, keep only the first of them and unlink the rest. Return the resulting list as an array.
Work as you would on real nodes: walk the list once and skip over repeats instead of building a set.
Example 1
Input: values = [1,1,2] Output: [1,2] Explanation: The second 1 is unlinked.
Example 2
Input: values = [1,1,2,3,3] Output: [1,2,3] Explanation: Each run of equal readings shrinks to a single node.
Constraints
- 0 <= values.length <= 2 * 10^4
- -10^5 <= values[i] <= 10^5
valuesis sorted in non-decreasing order
Hint 1
Compare each node with the one just before it.
Hint 2
A node is kept only when its value differs from the previous kept value.
Good practice for: Backend Developer, Full Stack Developer, Embedded Systems Engineer, Data Engineer, Automation Test Engineer
Run checks your code on 3 sample tests. Submit runs all 8 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.