Unique, sorted
Inputs
values is a list of 0 to 16 whole numbers in increasing order, each from 0 to 12. Numbers may repeat.
Your tasks
- Create an empty list
unique. - Use a loop over
values. Add a number touniqueonly whenuniqueis empty or its last number is different. - Complete
uniqueSortedso it returnsunique. Return it, do not print it.
Example
With values = [1, 1, 2, 3, 3, 3, 7], uniqueSorted returns [1, 2, 3, 7].
Rules
- Because the list is sorted, equal numbers sit next to each other.
Test data
TEST DATA 1: values is [1, 1, 2, 3, 3, 3, 7]
TEST DATA 2: values is []
Practice focus
Two pointers and sliding windows: loops that move two positions instead of one. Two pointers and sliding windows turn many quadratic answers into linear ones.