Zoblik International operates a vast network of environmental monitoring stations across various biomes. Each station is equipped with multiple sensors designed to capture different environmental parameters, such as temperature, humidity, and atmospheric pressure. To ensure data integrity and for advanced analytics, these sensors often record their readings in a pre-sorted manner, based on the magnitude of the measurement itself (e.g., from lowest temperature to highest, or lowest pressure to highest).
However, data streams from different sensors at the same station need to be integrated into a single, comprehensive chronological record for trend analysis. Your task is to simulate this integration process.
Given two separate lists of sensor readings, each already sorted in non-decreasing order, your goal is to merge them into a single, combined list that maintains the non-decreasing order. This unified list will represent the complete ordered data stream from both sensors.
The first line of input contains an integer 'T', representing the number of test cases.
For each test case:
For each test case, output a single line containing 'N+M' space-separated integers, which are the elements of the merged, sorted list of readings.
1 <= T <= 1000 <= N, M <= 1041 <= Ai, Bi <= 1051 <= T <= 100; 1 <= n, m <= 10^4; 1 <= Ai, Bi<= 10^5
Sample Input:
2 5 2 1 3 3 4 4 5 6 6 2 1 3 3 3 3 4 9 11Explanation of First Test Case:
Let's consider the first test case:
Sensor A readings (N=5):
[1, 3, 3, 4, 4]Sensor B readings (M=2):
[5, 6]We use a two-pointer approach to merge them:
- Initialize pointers:
ptr_A = 0(pointing to1),ptr_B = 0(pointing to5). Merged list:[].- Compare
A[0](1) andB[0](5). Since1 <= 5, add1to merged list. Merged:[1]. Incrementptr_A.- Compare
A[1](3) andB[0](5). Since3 <= 5, add3to merged list. Merged:[1, 3]. Incrementptr_A.- Compare
A[2](3) andB[0](5). Since3 <= 5, add3to merged list. Merged:[1, 3, 3]. Incrementptr_A.- Compare
A[3](4) andB[0](5). Since4 <= 5, add4to merged list. Merged:[1, 3, 3, 4]. Incrementptr_A.- Compare
A[4](4) andB[0](5). Since4 <= 5, add4to merged list. Merged:[1, 3, 3, 4, 4]. Incrementptr_A.- Now,
ptr_Ais5, which equals N. Sensor A is exhausted. Append all remaining elements from Sensor B to the merged list.- Remaining elements in B:
[5, 6].- Final Merged list:
[1, 3, 3, 4, 4, 5, 6].Sample Output:
1 3 3 4 4 5 6 1 3 3 3 3 4 9 11
Two Pointers, Arrays
Goldman Sachs, Juniper Networks, LinkedIn, Microsoft, Snapdeal, Synopsys, Zoho
Start coding and your submissions will appear here.