Sort List Problem

Sort List Problem — ExecCode Hard DSA Practice

Solve the Sort List problem on ExecCode. Free online hard DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given the head of a linked list, return the list after sorting it in ascending order. Aim for O(n log n) time and O(1)/O(log n) space (merge sort).

Examples

Input head = [4, 2, 1, 3]; Output [1, 2, 3, 4]

Constraints

0 ≤ n ≤ 5·10^4 -10^5 ≤ Node.val ≤ 10^5

Practice Sort List free on ExecCode. Browse DSA problems, topic map, and placement guides.