Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Longest Consecutive Sequence

Python data engineering interview problem. Difficulty: beginner. Pattern: Hashing. About 10 minutes. Free to practice.

Length of the longest run of consecutive integers. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

Implement longest_consecutive(nums: list) -> int returning the longest consecutive sequence length. (1..4).

Requirements

  • Empty list returns 0.

Constraints

  • Nums may be unsorted and may contain duplicates.

Examples

Input: longest_consecutive([100, 4, 200, 1, 3, 2]) Output: 4 1,2,3,4 form a run.

Topics: lakebench, python, set, sequence.

More Python interview questions · All interview problems · Learn data engineering

beginner

Longest Consecutive Sequence

Interview-style drill: Length of the longest run of consecutive integers.

Implement `longest_consecutive(nums: list) -> int` returning the longest consecutive sequence length. Example: `[100, 4, 200, 1, 3, 2]` → `4` (1..4). Keep the harness.