✅Simple Java Solutions with explanation
Algorithm:\n1. Create an empty hash.\n2. Insert all array elements to hash.\n3. Do following for every element arr[i]\n4. Check if this element is the starting 
# Algorithm:\n1. Create an empty hash.\n2. Insert all array elements to hash.\n3. Do following for every element arr[i]\n4. Check if this element is the starting point of a subsequence. To check this, simply look for arr[i]\n1 in the hash, if not found, then this is the first element a subsequence.\n5. If this element is the first element, then count the number of elements in the consecutive starting\nwith this element. Iterate from arr[i] + 1 till the last element that can be found.\n6. If the count is more than the previous longest subsequence found, then update this.\n\n# Code\n```\nclass Solution {\n    public int longestConsecutive(int[] nums) {\n        if (nums.length == 0) return 0;\n        HashSet<Integer> set = new HashSet<>();\n        for (int n : nums){\n            set.add(n);\n         }\n\n        int count = 1;\n\n        for (int num : nums) {\n            if (!set.contains(num - 1)) {\n                int tempCount = 1;\n                while (set.contains(num + 1)) {\n                    tempCount++;\n                    num++;\n                }\n                count = Math.max(count, tempCount);\n            }\n\n            if (count > nums.length / 2) break;\n        }\n\n        return count;\n    }\n\n}\n```\n## For additional problem-solving solutions, you can explore my repository on GitHub: [GitHub Repository](https://github.com/ahmedna126/java_leetcode_challenges)\n\n\n\n![abcd1.jpeg](https://assets.leetcode.com/users/images/ddabacf2-a0d6-4416-bb2f-ed36cae3d741_1695494595.861337.jpeg)\n
['Java']