class Solution:
# @param A : tuple of integers
# @return an integer
def longestConsecutive(self, arr):
numSet=set(arr)
maxCount=0
for num in arr:
if not num in numSet: #already tested before
continue
count=1
for step in [1,-1]:#try forwad and backward
currentNum=num+step
while currentNum in numSet: #keep moving till currentNum not found
numSet.remove(currentNum)
count+=1
currentNum+=step
maxCount=max(maxCount,count)
return maxCount