Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Leetcode Linked List Basics
00:00
5 left

Leetcode Linked List Basics

EasyPython

Problem

Typical leetcode linked list questions

Implement the standard linked-list reversal task. Given the head of a singly linked list, reverse the links in place and return the new head.

The input is a ListNode reference, where each node has val and next fields. Return a ListNode reference representing the reversed list. The list may be empty. Example: [1, 2, 3] becomes [3, 2, 1].

Constraints

  • 0 <= number of nodes <= 5000
  • -5000 <= node.val <= 5000
  • The list is singly linked and contains no cycles

Function Signature

def reverse_list(head):
Interviewer

Your question is Leetcode Linked List Basics. Start with the requirements in the Question tab.

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.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.