Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-066

Palindrome Linked List

Problem

Check whether a singly linked list reads the same forwards and backwards.

values holds the node values in order. Use two pointers moving inward from both ends.

Return True for a palindrome, including the empty list, and False otherwise.

Hint

Compare the first value with the last, the second with the second-to-last, and so on.

Test cases

case 1
in: [[1,2,2,1]]
expected: true
case 2
in: [[1,2]]
expected: false
case 3
in: [[]]
expected: true
case 4
in: [[1,2,1]]
expected: true
case 5
in: [[1,2,3]]
expected: false
Starter codePython
def is_palindrome_list(values):
    # Your code here
    pass

5 test cases · run your code against them in the editor