InferenceAI

Enter at least two characters to search.

Start free

Palindrome List

easyLinked Lists15 min10 XP

Return True if the linked list is a palindrome.

Linked lists are given and returned as Python lists of node values, from head to tail. Think in terms of nodes and pointers; the list format just makes the tests readable.

Requirements

  • With real nodes: find the middle with slow/fast pointers, reverse the second half, and compare, all in O(1)O(1) extra space.

Examples

EXAMPLE WALKTHROUGHeven

A guided view of the published example, not a trace of your code.

INPUT[[1,2,2,1]]
TASKpalindrome_list()
EXPECTED OUTPUTtrue

Start with the input values shown in this example.

Example 1 of 3

Input: values = [1,2,2,1]

Output: true

Explanation: even

Input: values = [1,2]

Output: false

Explanation: not a palindrome

Input: values = [1,2,1]

Output: true

Explanation: odd

Hint 1

Compare the first half with the reversed second half.

Topics

DSALinked ListsPython