Skip to content

ORIGINAL CODING QUESTION

Longest mirrored glyph span

Return the length of the longest nonempty contiguous palindromic glyph sequence.

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 ≤ 30; each glyph is an integer in [0,25]. Equal integers mean equal characters.

Example 1

Input

5 0 1 2 1 0

Output

5

The entire sequence is mirrored.

Example 2

Input

4 0 1 1 2

Output

2

The repeated middle glyphs form length 2.

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

A palindrome expands around a center.

Hint 2

Handle both odd and even centers.

Hint 3

Extend while the two boundary glyphs are equal.

Practice this question

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

Open practice workspaceBrowse the question library →