Detect a duplicate with a seen-set05.02
Scan left to right. If contains(a[i]), you found a duplicate. Else insert a[i]. First repeat is the first time contains hits. All-unique never hits.
Query then insert. Insert-then-query would see the value you just added and false-positive every index.
Same skill, three traces. Read all three before you try it.
01repeat 1 - given
a = [4, 1, 9, 1]- walk
4new,1new,9new,1hits at index3- result
1
02all unique - given
a = [4, 1, 9]- walk
never contains
- result
- no duplicate
03empty - given
a = []- walk
no indices
- result
- no duplicate
firstDup(a).a is an array of integers.Scan left to right. If
contains(a[i]), return that value. Else insert a[i]. Query before insert.a = [4, 1, 9, 1] → 1.a = [4, 1, 9] → no duplicate.a = [] → no duplicate.constraintsa is a list of integers and may be empty.
- Contains Duplicate0/3 skills ready · hash sets · easyopen
- Contains Duplicate0/3 skills ready · hash sets · easyopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.