public static int longestConsecutive(int[] num) {
        int maxLen = 0;
        
        // Add each number in the array to the hashset first
        HashSet<Integer> set = new HashSet<Integer>();
        for(int i =0; i<num.length; i++){
        	set.add(num[i]);
        }
        
        for(int i=0; i<num.length; i++){
        	int currentLen = 0;
        	int currentNum = num[i];
        	
        	if(set.contains(currentNum)){
        		currentLen ++;
        		set.remove(currentNum);
        		int temp = currentNum + 1;
        		while(set.contains(temp)){
        			currentLen ++;
        			set.remove(temp);
        			temp ++;
        		}
        		
        		temp = currentNum - 1;
        		while(set.contains(temp)){
        			currentLen ++;
        			set.remove(temp);
        			temp --;
        		}
        	}
        	
        	if(currentLen > maxLen)
        		maxLen = currentLen;
        	
        	
        }
		
		return maxLen;
        
    }