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

Sort List

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Sort List** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Merge sort on linked list (find mid + merge) **Edge Cases to Consider:** - (1) Empty list - (2) Single node - (3) Already sorted

Examples

Example 1
Input: [4,2,1,3]
Output: [1,2,3,4]
Explanation: Basic sort
Example 2
Input: [-1,5,3,4,0]
Output: [-1,0,3,4,5]
Explanation: Mixed negatives
Example 3
Input: []
Output: []
Explanation: Empty 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

  • ▪Empty list
  • ▪Single node
  • ▪Already sorted
Frequently Asked At
AmazonGoogleMicrosoftAdobe