PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/Amazon

Merge two sorted arrays in-place

Last updated: Mar 29, 2026

Quick Overview

This question evaluates array-manipulation and in-place algorithm skills, including understanding of sorted-data merging, index/pointer management, and analysis of time and space complexity within the Coding & Algorithms domain.

  • hard
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Merge two sorted arrays in-place

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Technical Screen

Given two arrays `arr1` and `arr2`, both sorted in **ascending** order. - Modify `arr1` **in-place** to contain all elements from `arr1` and `arr2` in **ascending** order. - **Do not** allocate an additional array for the merge result. Assumptions/clarifications you may use: - `arr1` has enough extra capacity at the end to hold all elements of `arr2` (e.g., `arr1` length is `m + n`, where the first `m` entries are valid and the last `n` are empty slots), and `arr2` has length `n`. - You are given `m` and `n`. Follow-ups: 1. How would you adapt your approach if both arrays were sorted in **descending** order? 2. If the arrays were **not sorted**, what would you do (and what are the time/space trade-offs)? Define the time and space complexity of your approach.

Quick Answer: This question evaluates array-manipulation and in-place algorithm skills, including understanding of sorted-data merging, index/pointer management, and analysis of time and space complexity within the Coding & Algorithms domain.

Related Interview Questions

  • Count Connected Components in an Undirected Graph - Amazon (medium)
  • Find Unique Target-Sum Pairs - Amazon (easy)
  • Find Valid IP Addresses in Files - Amazon (medium)
  • Implement Optimal Bucket Batching - Amazon (hard)
  • Implement Cache and Rotate Matrix - Amazon (medium)
Amazon logo
Amazon
Feb 8, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
7
0
Loading...

Given two arrays arr1 and arr2, both sorted in ascending order.

  • Modify arr1 in-place to contain all elements from arr1 and arr2 in ascending order.
  • Do not allocate an additional array for the merge result.

Assumptions/clarifications you may use:

  • arr1 has enough extra capacity at the end to hold all elements of arr2 (e.g., arr1 length is m + n , where the first m entries are valid and the last n are empty slots), and arr2 has length n .
  • You are given m and n .

Follow-ups:

  1. How would you adapt your approach if both arrays were sorted in descending order?
  2. If the arrays were not sorted , what would you do (and what are the time/space trade-offs)?

Define the time and space complexity of your approach.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amazon•More Software Engineer•Amazon Software Engineer•Amazon Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.