Skip to content

ORIGINAL CODING QUESTION

Count mirrored glyph spans

Count all nonempty palindromic contiguous glyph sequences. Equal content at different indexes counts separately.

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

3 0 0 0

Output

6

All six nonempty spans are mirrored.

Example 2

Input

3 0 1 2

Output

3

Only the three singleton spans qualify.

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

Every palindrome has a center.

Hint 2

Odd and even centers both contribute.

Hint 3

Each successful expansion adds one distinct indexed span.

Practice this question

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

Open practice workspaceBrowse the question library →