Question bank › Sliding Window
Dsa Sliding Window Medium

Consecutive Number Sum

Given an array of integers `sequence`, determine the length of the longest consecutive sequence of numbers that sum to a given target `t`. Input: - The first line contains an integer n (1 ≤ n ≤ 10^5), the number of elements in the array. - The second line contains n space-separated integers, representing the elements of the array (-10^4 ≤ sequence[i] ≤ 10^4). - The third line contains an integer t (1 ≤ t ≤ 10^5), the target sum. Output: - An integer representing the length of the longest consecutive sequence that sums to `t`. Example: Input: 5 1 2 3 4 5 7 Output: 3

Key concepts

sliding_windowmathematicsarrays

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.