Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
A job lists the partitions it wrote, one entry per file. Each partition date appears once for every file in it, so the same date is listed several times. The list is already sorted. The next step needs each date once.
Write dedupe_sorted(values). values is a sorted list. Return a dict {"length": int, "values": list}: the number of distinct values, and the distinct values in the same order.
Function to write
dedupe_sorted(values: list) -> dictA dict with the number of distinct values and the distinct values in order.
How to approach it
Keep a write position. Compare each value to the last value you kept, not to the first one. Equal values are always side by side.
Sample cases
+ 3 held back until you submit
repeated partition dates
Three distinct dates. Each repeated date is kept once, in order.
Input
Argument 1
[
'2026-01-01',
'2026-01-01',
'2026-01-02',
'2026-01-03',
'2026-01-03',
'2026-01-03'
]Returns
{
'length': 3,
'values': [
'2026-01-01',
'2026-01-02',
'2026-01-03'
]
}already unique
No repeats, so the list comes back unchanged with the same length.
Input
Argument 1
[
1,
2,
3,
4
]Returns
{
'length': 4,
'values': [
1,
2,
3,
4
]
}all the same
Every value repeats, so only one 7 is left.
Input
Argument 1
[
7,
7,
7,
7
]Returns
{
'length': 1,
'values': [
7
]
}empty list
Nothing to remove: length 0 and an empty list.
Input
Argument 1
[] (empty list)
Returns
{
'length': 0,
'values': []
}Constraints
length is the number of values in the output.{"length": 0, "values": []}.set, and do not search the output list for each value.Worked example
Take [1, 2, 2, 3]. Start with write at 1, because the first value is always kept. Look at the value at position 1, which is 2. Compare it to the last value kept, 1 (at position write - 1). They are different, so keep it at position 1 and move write to 2. Look at the next value, 2. The last value kept is 2, so skip it. Look at 3: different from 2, so keep it at position 2 and move write to 3. The answer is {"length": 3, "values": [1, 2, 3]}.
The trap: comparing each value to the first value of the list keeps the second 2, because 2 is different from 1.
What this tests
Remove duplicates from a sorted array, a classic two-pointer problem. The read pointer visits every value, and the write pointer marks where the next kept value goes. Because the list is sorted, you only need to compare with the last value kept. Data engineers use the same idea to collapse repeated keys in sorted files.
dedupe_sorted(values: list) -> dictSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.