Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse a Singly Linked List

Medium
CodingRecursionStackDynamic ProgrammingLinked Lists
Asked 1mo ago|
Google
Google
Asked 10 times

Problem

Given the head of a singly linked list, reverse the list, and return the new head node. The linked list is defined as follows:

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

Constraints

  • 0 <= number of nodes <= 5000
  • -5000 <= Node.val <= 5000

Function Signature

def reverse_list(head: Optional[ListNode]) -> Optional[ListNode]:
Practicing as: Software Engineer interview at ConnectiCare

Hi, I'll play your ConnectiCare interviewer for the Software Engineer role. Candidates describe these interviews as mostly positive and moderately difficult, so expect me to be friendly and conversational. Take your time with the question above and answer like we're in the room.

You are practicing as a guest. Sign up free to run your code against the sample data. Your draft stays right here.

Sign up freeI have an account
def solve(rows):
    counts = {}
    for row in rows:
        ...
    return result
Sign up to unlock solutions
ConnectiCare Software Engineer Interview QuestionsAlten Mobile Engineer Interview QuestionsGoogle Embedded Engineer Interview QuestionsConnectiCare Interview QuestionsQuantum Health Mobile Engineer Interview Questions
Next questions
PwCReverse a Singly Linked ListEasyCopelandReverse Singly Linked ListEasyNTT DATAReverse a Singly Linked ListEasy