Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Reverse Linked List II (medium)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

Given the head of a singly linked list and two positive integers left and right where left <= right, reverse all the nodes from the left to the right position, and return the updated list.

Examples

Example 1:

  • Input: [7, 8, 9, 10, 11], left = 2, right = 4
  • Expected Output: [7, 10, 9, 8, 11]
  • Justification: The nodes from position 2 to 4 (8, 9, 10) are reversed to become 10, 9, 8.

Example 2:

  • Input: [1, 2, 3, 4, 5, 6], left = 2, right = 5
  • Expected Output: [1, 5, 4, 3, 2, 6]
  • Justification: The nodes from position 2 to 5 (2, 3, 4, 5) are reversed to become 5, 4, 3, 2.

Example 3:

  • Input: [5, 6, 7, 8, 9], left = 1, right = 3
  • Expected Output: [7, 6, 5, 8, 9]
  • Justification: The nodes from position 1 to 3 (5, 6, 7) are reversed to become 7, 6, 5.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible