Example 1 · empty
- Arguments
- values
[]
- Expected return
[]
Test data
- Input
{"values":[]}- Expected output
[]
func DeduplicateSorted(values []int) []intExamples use {"values": [...]}.
The runner calls your functions directly; you do not need to parse JSON.
[]
[]
{"values":[]}[]
[ -3, -3, 0, 0, 0, 4, 4 ]
[ -3, 0, 4 ]
{"values":[-3,-3,0,0,0,4,4]}[-3,0,4]
[ -2, 0, 5 ]
[ -2, 0, 5 ]
{"values":[-2,0,5]}[-2,0,5]
[ 7, 7, 7, 7 ]
[ 7 ]
{"values":[7,7,7,7]}[7]
Equal values are contiguous in a nondecreasing sequence. Keeping the first item of each run retains every distinct value exactly once, and retaining encounter order preserves ascending output. No set or search through earlier runs is necessary.
O(n) time and O(1) auxiliary space excluding the returned sequence, which contains at most n values.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.