A craft strand is a singly linked chain of bead tokens, each carrying an integer. Determine whether the strand is a mirror image of itself: the sequence of values from head to tail is identical to the sequence from tail to head.
Line 1: an integer n, the number of beads.
Line 2: n space-separated integers, the bead values from head to tail (empty line when n is 0).
Print YES if the strand reads the same in both directions, otherwise NO.
Example 1
Input
5 2 7 4 7 2
Expected
YES
Explanation
Reading forward gives 2 7 4 7 2, the same as reading backward, so the strand is a mirror: YES.
Example 2
Input
4 1 2 2 3
Expected
NO
Explanation
Forward is 1 2 2 3 but backward is 3 2 2 1, which differ, so NO.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →