0Pricing
Competitive Programming Academy · Lesson

Merge Two Sorted Sequences

Walk both lists with one pointer each.

The Merge Step

Given two sorted lists, combine them into one sorted list. This merge is the heart of merge sort and shows up everywhere. 🔗

Two Inputs, One Pointer Each

Give each list its own pointer, both starting at index 0. You will walk them forward together, never backward.

i = 0
j = 0

All lessons in this course

  1. Two Pointers on a Sorted Array
  2. Find a Pair with a Given Sum
  3. Remove Duplicates In Place
  4. Merge Two Sorted Sequences
← Back to Competitive Programming Academy