Skip to content

ORIGINAL CODING QUESTION

Mirror check that ignores spaces

A headline is encoded as glyphs: 1 to 26 stand for the letters a to z and 0 stands for a space. Ignoring every space, print 1 if the letters read the same forwards and backwards, otherwise 0. A headline with no letters counts as a mirror and prints 1.

Open practice workspace

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

Input and output

First integer n, then n glyphs. Print 1 or 0.

Constraints

1 ≤ n ≤ 200; each glyph is in [0, 26].

Example 1

Input

6
1 2 0 2 0 1

Output

1

Without spaces the letters are a b b a, which reads the same both ways.

Example 2

Input

5
3 1 0 2 3

Output

0

Without spaces the letters are c a b c; reversed they read c b a c.

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

Spaces never affect the answer, so you must skip them.

Hint 2

Use one pointer from the left and one from the right that move toward each other.

Hint 3

Advance each pointer past zeros; if the two letters differ print 0, otherwise move both inward until they meet and print 1.

Practice this question

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

Open practice workspaceBrowse the question library →