Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

68. Reverse Linked List

EasyDay 21 of 60Linked List

Given the head of a singly linked list, reverse the list and return the new head. Try to do it by changing the next pointers in place, without creating new nodes.

Example 1
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Example 2
Input: head = [1,2]
Output: [2,1]
Example 3
Input: head = []
Output: []
Constraints
  • The list has 0 to 5000 nodes
  • -5000 <= Node.val <= 5000
Hints
Frequently asked at: Amazon, Microsoft, Apple, Adobe, TCS, Infosys
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min