Ctrl K

Symmetric Bead String

Easy
Beads are threaded on a string, and each bead carries a digit. The string is given as the singly linked list head, one node per bead. Return True if the digits read the same from the start and from the end of the string, and False otherwise. Copying the values into an array is the easy way; try to use only O(1) extra memory.
Example 1
head=list_node([4, 7, 1, 7, 4]) → True

The beads read the same from either end: 4, 7, 1, 7, 4.

Example 2
head=list_node([3, 3, 5]) → False

Left to right it is 3, 3, 5; right to left it is 5, 3, 3. Not symmetric.

Example 3
head=list_node([8]) → True
Constraints
  • The list has between 1 and 10⁵ nodes
  • 0 ≤ Node.val ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsList Folded From Both Ends MediumMirror Pairs in a List MediumLeaders of a List MediumZip Two Sorted Chains EasyCut Out Matching Nodes Easy
loading Python…
Input
head=list_node([4, 7, 1, 7, 4])
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 83 tests on the server, hidden ones included.