⚡️ Tryprepforge
Backend Engineer Senior programming

Design a function to sort a linked list in O(n log n) time using the merge sort algorithm. The function should return the head of the sorted linked list. Example 1: Input: head = 4 -> 2 -> 1 -> 3 Output: 1 -> 2 -> 3 -> 4 Example 2: Input: head = -1 -> 5 -> 3 -> 4 -> 0 Output: -1 -> 0 -> 3 -> 4 -> 5 Constraints: - The number of nodes in the linked list is in the range [0, 5 * 10^4]. - -10^5 <= Node.val <= 10^5.

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Backend Engineer Interview Prep

Link copied to clipboard