Dsa
Two Pointers
Easy
Consecutive Common Interest
Two users have lists of interests represented by sorted unique IDs. We define a 'common streak' as a sequence of integers x, x+1, x+2, ... that appear in both users' interest lists. Find the length of the longest such common streak.
Input Format:
Line 1: N, M (number of interests for User A and B)
Line 2: N sorted unique integers
Line 3: M sorted unique integers
Example:
Input:
7 6
1 2 3 5 6 10 11
2 3 4 5 6 11
Output:
2
Explanation: The common interests are {2, 3, 5, 6, 11}. Streaks are {2, 3} length 2, {5, 6} length 2, and {11} length 1. Max length is 2.
Key concepts
two_pointersintersection
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