PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency in array manipulation, in-place algorithms, and reasoning about time and space complexity when merging sorted sequences.

  • Medium
  • Meta
  • Coding & Algorithms
  • Machine Learning Engineer

Merge two sorted arrays in-place

Company: Meta

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You are given two nondecreasing arrays A and B, where A has enough trailing empty slots to hold all elements of B. Merge B into A in-place so that A remains sorted. Describe and implement an algorithm that runs in O(m+n) time and O( 1) extra space, and argue correctness.

Quick Answer: This question evaluates proficiency in array manipulation, in-place algorithms, and reasoning about time and space complexity when merging sorted sequences.

Merge sorted B into A, where A has trailing slots, and return A after the in-place merge.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([1,2,3,None,None,None], 3, [2,5,6], 3)

Expected Output: [1, 2, 2, 3, 5, 6]

Explanation: Merge from the back into trailing slots.

Input: ([None], 0, [1], 1)

Expected Output: [1]

Explanation: Empty A prefix is supported.

Input: ([1], 1, [], 0)

Expected Output: [1]

Explanation: Empty B leaves A unchanged.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)