Problem
Submissions

Solution: Longest Consecutive Sequence

Statement

Naive approach

A naive approach to solve this problem would be to sort the input array and then iterate through the sorted array. For each element, we check if the next consecutive element exists in the sorted array. If it does, we keep incrementing until we reach the end of the sequence. After reaching the end of the sequence, we compare its length with the previous longest sequence found and update the result accordingly. The time complexity of this approach is O(nlogn)O(n \log n), and the space complexity is O(1)O(1).

Optimized approach using union find

Problem
Submissions

Solution: Longest Consecutive Sequence

Statement

Naive approach

A naive approach to solve this problem would be to sort the input array and then iterate through the sorted array. For each element, we check if the next consecutive element exists in the sorted array. If it does, we keep incrementing until we reach the end of the sequence. After reaching the end of the sequence, we compare its length with the previous longest sequence found and update the result accordingly. The time complexity of this approach is O(nlogn)O(n \log n), and the space complexity is O(1)O(1).

Optimized approach using union find