Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Reverse a Singly Linked List

Easy
CodingRecursionLinked ListspointersAsked 1 times

Problem

Given the head of a singly linked list, reverse the list and return the new head. Each node contains an integer value and a next pointer. You must reverse the links in-place rather than creating a second list.

Constraints

  • 0 <= number of nodes <= 5000
  • -5000 <= Node.val <= 5000
  • The list is singly linked

Function Signature

def reverse_linked_list(head):
Practicing as: Security Engineer interview at PwC

Hi, I'll play your PwC interviewer for the Security Engineer role. Candidates describe these interviews as mixed and on the easier side, so expect me to be professional and fair. 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
PwC Security Engineer Interview QuestionsPwC Interview Questions
Next questions
NTT DATAReverse a Singly Linked ListEasyAccentureReverse a Singly Linked ListEasyCopelandReverse Singly Linked ListEasy