Merge K Sorted Arrays Problem Statement

You are provided with 'K' different arrays/lists, each sorted in ascending order. Your task is to merge all these arrays/lists into one sorted array/list in ascending order.

Input:

The first line contains an integer T, indicating the number of test cases. 
The first line of each test case contains an integer K, the number of arrays/lists.
The following 2*K lines for each test case include:
- A line with an integer N, representing the size of that array.
- A line with N space-separated integers denoting the elements of the array.

Output:

The output consists of a single line for each test case, containing space-separated elements of the merged and sorted array.

Example:

Input:
T = 1
K = 2
Array 1: N = 3, Elements = [1, 3, 5]
Array 2: N = 4, Elements = [2, 4, 6, 8]
Output:
1 2 3 4 5 6 8

Constraints:

  • 1 <= T <= 5
  • 1 <= K <= 5
  • 1 <= N <= 20
  • -105 <= DATA <= 105
  • Time limit: 1 sec

Note:

The printing of the output has been handled. You only need to implement the function.
AnswerBot
4mo

Merge K sorted arrays into one sorted array in ascending order.

  • Iterate through all arrays/lists and merge them into one sorted array using a priority queue or merge sort algorithm.

  • Ensure to handle edg...read more

Help your peers!
Select
Add answer anonymously...

Bounteous x Accolite Software Developer interview questions & answers

A Software Developer was asked 12mo agoQ. Introduce yourself.
A Software Developer was asked Q. Tell me about Spring Boot.
A Software Developer was asked Q. Implement a Binary Search Tree (BST) from scratch, including tree traversal algo...read more

Popular interview questions of Software Developer

A Software Developer was asked 12mo agoQ1. Tell me about Spring Boot.
A Software Developer was asked Q2. Implement a Binary Search Tree (BST) from scratch, including tree traversal algo...read more
A Software Developer was asked Q3. Write code to split an array of integers into two subarrays where both arrays ha...read more
Bounteous x Accolite Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits