Detect a repeat visit08.03
contains(x) true means you have already committed to x. That is a cycle, a duplicate path, or a second look at the same grid cell. Return, skip, or count it. Do not expand it again.
First time is insert. Second time is the repeat. Self-loops are an immediate repeat if you marked on enter.
Same skill, three traces. Read all three before you try it.
01cycle - given
a = [1, 2, 1]as a pointer walk from0- walk
seen
1,2, then1hits- result
- repeat
1— cycle
02fresh - given
a = [4, 1, 9]- walk
each insert is new
- result
- no repeat
03empty - given
a = []- walk
no visits
- result
- no repeat
firstRepeat(a).a is an array of integers. For pointer walks, a[i] is the next index.Walk, inserting into seen. Return the first value whose contains is already true, or none.
a = [1, 2, 1] as a pointer walk from 0 → repeat 1 — cycle.a = [4, 1, 9] → no repeat.a = [] → no repeat.constraintsa is a list of integers and may be empty. Pointer walks use a[i] as the next index; those indices are valid.
- Happy Number0/2 skills ready · hash sets · easyopen
- Happy Number0/2 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.