Skip to content
CampusEduX

Longest Consecutive Sequence

Mediumjavapythonccppjavascript

Given an unsorted array, find the length of the longest run of consecutive integers (values differing by exactly 1), regardless of their positions in the array.

Input Format

The first line contains an integer N. The second line contains N space-separated integers.

Output Format

Print the length of the longest consecutive sequence.

Related Problems

  • Zero Sum Subarray
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Longest Subarray with Sum K
    Medium · java, python, c, cpp, javascript
    Solve Problem
  • Group Anagrams
    Medium · java, python, c, cpp, javascript
    Solve Problem

Input (stdin)

Output

Run your code to see output here...