Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Vote For New Content
Sort List (medium)
On this page

Problem Statement

Given a head of the linked list, return the list after sorting it in ascending order.

Examples

  1. Example 1:

    • Input: [3, 1, 2]
    • Expected Output: [1, 2, 3]
    • Justification: The list is sorted in ascending order, with 1 coming before 2, and 2 before 3.
  2. Example 2:

    • Input: [4]
    • Expected Output: [4]
    • Justification: A list with a single element is already sorted.
  3. Example 3:

    • Input: [9, 8, 7, 6, 5, 4, 3, 2, 1]
    • Expected Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page