Your question is Check Linked List Palindrome. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Applied Network Solutions uses singly linked lists to represent ordered packet-processing stages. Write a function that determines whether the sequence of stage values reads identically from left to right and right to left.
Return True when the linked list is a palindrome and False otherwise. Your preferred solution must run in O(n) time and use O(1) auxiliary space. The list should be restored to its original order before the function returns.
The input is head, either None or a reference to the first node of a singly linked list. Each node has an integer val field and a next field containing another node or None. Return a Boolean.
For the JSON test cases below, each input array represents the linked list from head to tail. The test harness converts the array into linked nodes before calling the function.
def is_palindrome(head):