@@ -0,0 +1,1006 @@
+package problems;%0A%0Aimport java.util.HashMap;%0A%0Apublic class LongestConsecutiveSequence %7B%0A    public int longestConsecutive(int%5B%5D num) %7B%0A        if (num == null %7C%7C num.length == 0)%0A            return 0;%0A%0A        HashMap%3CInteger, Integer%3E map = new HashMap%3CInteger, Integer%3E();%0A        for (int k : num)%0A            map.put(k, 1);%0A%0A        int max = 0;%0A        for (int k : num) %7B%0A            if (!map.containsKey(k))%0A                continue;%0A            int end = k + map.get(k) - 1, next = end + 1;%0A            while (map.containsKey(next)) %7B%0A                end = next + map.remove(next) - 1;%0A                next++;%0A            %7D%0A%0A            map.put(k, end - k + 1);%0A            max = Math.max(max, end - k + 1);%0A        %7D%0A        return max;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        LongestConsecutiveSequence lcs = new LongestConsecutiveSequence();%0A%0A        int%5B%5D num = %7B -2, -3, -3, 7, -3, 0, 5, 0, -8, -4, -1, 2 %7D;%0A        System.out.println(lcs.longestConsecutive(num));%0A    %7D%0A%7D%0A

Add Longest Consecutive Sequence