VFlash: Fast, Accurate Visual Planning via Flash Primitive Decoding
u_Unrolled
DSA for AI/ML · Module 03: Two pointers

Lesson 3.4 of 10 in this module Unrolled Pro

Merge Sorted Array

Merge one sorted array into another that has room at the end, in place. From concatenating and sorting, to a forward merge that needs a copy, to filling from the back with three pointers in O(m + n) time and O(1) space. Then k sorted lists with a heap, data that doesn't fit in memory, and intersections.

about 10 min 4 Python examples 2 quick checks

Problem. nums1 has length m + n: its first m values are sorted, the last n slots are placeholders (zeros). nums2 holds n sorted values. Merge nums2 into nums1 in place so all m + n values are sorted.

text
nums1 = [1, 2, 3, 0, 0, 0], m = 3
nums2 = [2, 5, 6],          n = 3      →   nums1 = [1, 2, 2, 3, 5, 6]

ML context. Merging sorted runs is the heart of merge sort, of external sorting for datasets bigger than RAM, and of combining sorted shards: ranked results from several retrieval shards, sorted event logs from many machines, or sorted prediction files from parallel workers.


1. Step 1: Clarify

That's the preview. Modules 00–01 are free; this lesson is part of Unrolled Pro.
Staff AI & Pro Tier Lesson

Unlock "Merge Sorted Array"

The foundations are free forever. Unrolled Pro unlocks the complete lesson, production architectures, and 55 battle-tested ML system design case studies.

Everything included with Pro:
All 234+ Deep-Dive Lessons across transformer internals, inference, RAG & agents
55 Staff-Level ML & System Design Case Studies with mathematical capacity estimates
AI Engineer Sheet & Exercises with worked solutions, self-checks, and code
100 Landmark Research Papers guided walkthroughs & progress tracking
14-Day Money-Back Guarantee — 100% full refund if you aren't satisfied
View Plans & Unlock All Lessons

From ₹167/mo (~$2/mo) · Cancel anytime · Instant activation

100% Risk-Free: 14-day no-questions-asked money-back guarantee