Skip to content

ORIGINAL CODING QUESTION

Consecutive topic ID run

Return the length of the longest run of consecutive distinct integer values, regardless of their input order.

Open practice workspace

Original exercise · medium. Editorial role relevance does not imply a company has asked this question.

Input and output

n, then n integer values. Print one integer as described.

Constraints

1 ≤ n ≤ 200; -100 ≤ value ≤ 100. Inputs contain exactly the stated values.

Example 1

Input

6 100 4 1 3 2 2

Output

4

Values 1,2,3,4 form a run of four.

Example 2

Input

3 -2 0 -1

Output

3

The run -2,-1,0 has length three.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

Duplicate IDs do not extend a run.

Hint 2

Start only at values without a predecessor.

Hint 3

Advance from each start while the next value exists.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →