Problem 381650 · medium · Phase 03 Linear Management & Searching

Almost Symmetric Sequence

two pointers · palindromes

A sequence is symmetric if it reads the same forwards and backwards. Given a list of integers nums, return True if nums is symmetric or can be made symmetric by deleting at most one element, and False otherwise.

Examples

Input:  nums = [1, 2, 3, 2, 2, 1]
Output: True
Explanation: deleting the 2 at index 4 gives [1, 2, 3, 2, 1], which reads the same both ways.

Input:  nums = [4, 1, 3, 2, 4]
Output: False
Explanation: no single deletion works.

Constraints

  • 0 <= len(nums) <= 10**5
  • Target: O(n) time, O(1) extra space (do not build sliced copies).

Goals

  • Detect the first mismatch with a converging scan
  • Branch into two candidate sub-scans without allocating new lists
Starting Python…