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

Reverse Linked List

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Reverse Linked List** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Iterative prev/curr/next or recursive **Edge Cases to Consider:** - (1) Empty list - (2) Single node - (3) Two nodes

Examples

Example 1
Input: [1,2,3,4,5]
Output: [5,4,3,2,1]
Explanation: Basic reversal
Example 2
Input: [1,2]
Output: [2,1]
Explanation: Two nodes
Example 3
Input: [1]
Output: [1]
Explanation: Single node

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

  • ▪Empty list
  • ▪Single node
  • ▪Two nodes
Frequently Asked At
AmazonMicrosoftAppleMetaAdobeInfosysTCS