Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Recursive Reverse Linked List

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

Your question is Recursive 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

Searce cloud engineering workflows may process linked sequences of tasks or events that must be traversed in reverse order. Given the head of a singly linked list, reverse the list recursively and return the new head.

Formal Specification

The input is head, either None or a reference to a ListNode with fields val and next. The function must reverse the existing links in place, without creating replacement nodes, and return the head of the reversed list. The judge serializes the returned list as an array of values for verification.

Use the recursive call to reverse the suffix before reconnecting the current node. Do not use Python list operations to perform the reversal.

Constraints

  • 0 <= n <= 10^4
  • -10^9 <= node.val <= 10^9
  • The list is singly linked and acyclic
  • Reverse links in place without creating replacement nodes

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