Your question is Second Last and Uniqueness. 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.
HR Cloud processes ordered employee records using a singly linked list. Given the head of this list, return the value of the second-last node without modifying the list.
Your solution must traverse the list only once and use constant extra space. If the list contains fewer than two nodes, return None.
Implement second_last(head), where head is either None or a nested dictionary representing a node:
value field.next field containing another node or None.None when fewer than two nodes exist.Do not convert the list to an array, count its length in a separate traversal, or mutate any node.
def second_last(head):