Return early on a set hit03.02
If the question is does any value in the stream sit in the set, return true on the first contains hit. Do not finish the stream. Building the whole set first is only needed when later queries reuse it.
Early exit does not remove the value. The set is unchanged. A miss walks the whole stream.
Same skill, three traces. Read all three before you try it.
01hit early - given
a = [4, 1, 9], set is{1, 8}- walk
4out1hitsdo not scan
9- result
- true
02hit late - given
a = [4, 1, 9], set is{9}- walk
4,1out9hits- result
- true
03no hit - given
a = [4, 1, 9], set is{8, 2}- walk
all out
- result
- false
anyIn(a, s).a is the stream of integers. s is the lookup set.Scan a left to right. Return true on the first contains hit. Return false if none. Stop at the first hit. Do not remove from
s.a = [4, 1, 9], set is {1, 8} → true.a = [4, 1, 9], set is {9} → true.a = [4, 1, 9], set is {8, 2} → false.constraintsa is a non-empty list of integers. The lookup set is non-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.