DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
LinkedList

Reverse Linked List II (Sublist)

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Reverse Linked List II (Sublist)** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Find pre-node + reverse sublist + reconnect **Edge Cases to Consider:** - (1) left = right (no change) - (2) Reverse entire list - (3) Reverse up to last node

Examples

Example 1
Input: [1,2,3,4,5], 2, 4
Output: [1,4,3,2,5]
Explanation: Basic sublist reverse
Example 2
Input: [5], 1, 1
Output: [5]
Explanation: Single node, left=right
Example 3
Input: [1,2,3,4,5], 1, 5
Output: [5,4,3,2,1]
Explanation: Reverse entire list

Constraints

  • ▪The number of nodes in the list is in the range [0, 500]
  • ▪-100 <= Node.val <= 100
  • ▪Solve in-place without copying node structures

Watch Out For Edge Cases

  • ▪left = right (no change)
  • ▪Reverse entire list
  • ▪Reverse up to last node
Frequently Asked At
AmazonGoogleAdobeMicrosoft