Developer

This experience deserves a bigger screen

The DSA Visualizer is designed for deep focus,
side-by-side code, and real-time execution insight.

On small screens, that level of clarity can't be preserved.

Open on a tablet (landscape) or desktop for the intended experience.

Desktop experience preview

Merge Two Sorted ListsStep-by-Step Visualization

Merging two sorted lists is a key step in Merge Sort and a common list manipulation problem.

Problem Statement

You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list.

Approach

Use a dummy node to simplify the head logic. Compare the heads of both lists, attach the smaller node to the current result tail, and advance the pointer. Repeat until one list is empty, then attach the remaining part of the other list.

Time & Space Complexity

Time complexity is O(n + m). Space complexity is O(1) (excluding result list storage).

Interactive Visualization

Loading Interactive Visualizer...

Click "Play" or use arrow keys to step through the execution.