Valid Palindrome

EasyAcc. 96.2%
+15 XP 5

Mirror Symmetry Detection

A palindrome is a sequence that reads the same forwards and backwards. In data processing, detecting symmetry is crucial for everything from DNA analysis to string compression.

The Assignment

Your mission is to verify the symmetry of the input. Your function receives an array data.

  1. Place one pointer at the start (index 0) and another at the end (index length - 1).
  2. Move them toward each other.
  3. If at any point the values at the pointers don't match, print false and exit.
  4. If the pointers meet without any mismatches, print true.

01EXAMPLE 1

Input[1, 2, 1]
Outputtrue

Explanation: Reads same both ways.

Constraints

  • Ignore case if strings are involved (standard case: assume numbers).
ArraysTwo Pointers
JavaScript
Loading...
2 Hidden

Input Arguments

data[1,2,1]

Expected Output

true

Click RUN to test your solution