All problems

Mirror Bead Row

Easy · recursion

Ravi is stringing beads onto a thread. Each bead has a colour code, a whole number, and the beads are given in order from the left end to the right end as the list beads.

A row is a mirror row if it looks exactly the same when read from the right end to the left end. For example, the colours 3, 1, 4, 1, 3 form a mirror row, but 2, 7, 2, 7 do not.

Return true if the row is a mirror row, and false otherwise. A row with a single bead is always a mirror row.

Examples

Example 1

Input: beads = [3, 1, 4, 1, 3]

Output: true

Read from the right, the colours are 3, 1, 4, 1, 3, the same as from the left.

Example 2

Input: beads = [2, 7, 2, 7]

Output: false

From the right the colours are 7, 2, 7, 2, which is different.

Example 3

Input: beads = [5]

Output: true

Constraints