Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

QA Coding: Reverse Linked List

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is QA Coding: Reverse Linked List. 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.

You need to log in / sign up to run or submit.

Problem

A Thomson Reuters Westlaw processing component stores ordered result references in a singly linked list. Implement a function that reverses the list in place and returns the new head.

The nodes must be reused. Do not create replacement nodes or copy values into another collection. Your solution should clearly preserve the unreversed portion of the list while changing each node's next pointer exactly once.

Formal Specification

Input is head, either None or a reference to the first ListNode. Each node has a value field and a next field, where next is another ListNode or None. The input list is finite and acyclic. Return the new head after reversal. The grader serializes linked lists as JSON arrays for test cases and converts them to ListNode objects before calling the function.

Constraints

  • 0 <= n <= 10^5, where n is the number of nodes
  • Node values may be any Python values
  • The input list is finite and acyclic
  • No new linked-list nodes may be created

Function Signature

def reverse_linked_list(head):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output