In this article, we have solved the problem of Longest Consecutive Subsequence using the concept of Hash Map and Union Find.
Pre-requisites:
Hash MapUnion FindProblem Statement
You are provided with an unsorted array and your task is to find the length of the longest consecutive subsequence of elements from the array. The program should run in O(n) time, where n is the length of the array.
So lets understand the problem through an example:
Input:n=7arr[n]=[1,43,3,2,55,4,6]Output: 4
Expl...
Published on February 18, 2023 10:47