Continue learning
Practice related DSA questions in the same topic.
Return 1 as soon as an integer occurs a second time, otherwise return 0.
Return 1 as soon as an integer occurs a second time, otherwise return 0.
def solve(values, target): seen = [0] * (2001) i = 0 while (i < len(values)): key = (values[i] + 1000) if (seen[key] == 1): return 1 seen[key] = 1 i = (i + 1) return 0Check whether this value already owns a marked entry.
Check whether this value already owns a marked entry.
Cross off a roll number on first attendance. An already crossed number signals a repeat.
Use the bounded value range to keep a presence table.
O(n + U), U = 2001 time · O(U) auxiliary space
Worked example · {"values":[4,-2,1,-2],"target":0} ⇒ 1
Edge case 1 · {"values":[],"target":0} ⇒ 0
Edge case 2 · {"values":[5,6],"target":0} ⇒ 0
Negative numbers require an offset before indexing the table.
What structure would support arbitrary strings?