Solar Row Symmetry Check

Whether an integer array is a palindrome after at most one deletion

EasyTwo PointersPalindromeArrays

A solar farm records the signed tilt reading of each panel in a row, from left to right. Negative and positive readings represent opposite tilt directions.

A row passes its symmetry check when its sequence of readings is identical when read from either end. A technician may discard at most one reading suspected of coming from a faulty sensor. Discarding a reading closes the gap in the sequence; all remaining readings keep their original relative order.

Given the integer array readings, return whether the row can pass the symmetry check after discarding at most one reading.

An empty sequence and a sequence containing one reading both pass the check.

Examples

Example 1

Input: readings = [3,-2,7,-2,3]
Output: true

The readings already match from opposite ends, so no reading needs to be discarded.

Example 2

Input: readings = [4,1,9,1,6,4]
Output: true

Discarding the reading 6 leaves [4, 1, 9, 1, 4], which reads the same from either end.

Example 3

Input: readings = [1,2,3,4]
Output: false

Neither keeping every reading nor discarding any single reading makes the sequence symmetric.

Constraints

  • 0 <= readings.length <= 8000
  • -10^9 <= readings[i] <= 10^9

The intended solution runs in O(n) time and uses O(1) auxiliary space. The input array does not need to be modified.

Hints

Show hint 1

Compare readings from the two ends, moving inward while they agree.

Show hint 2

At the first mismatch, any successful single discard must remove one of those two mismatched readings.

Follow-up questions

What an interviewer might ask once you have a working solution.

  • If a discard is necessary, how would you return the smallest original index whose removal makes the sequence symmetric?
  • How would you compute the minimum number of readings that must be discarded when more than one discard is allowed?

Practice this with an AI interviewer

Explain your approach out loud, write Python or JavaScript, run it against hidden tests (including large inputs), and get a scored debrief.

Start this problem