mediumArraysPattern: Merge Sort / Quick Sort
Merge Unsorted Temperature Readings Solution
Problem Statement
You are given two unsorted arrays `temperatures1` and `temperatures2` containing temperature readings. Implement a function that sorts these readings using quick sort and merges them into a single sorted array `sortedTemperatures`, preserving duplicate temperatures.
Examples
Example 1:
Input:{"array1":[10,7,8,9,1,5],"array2":[4,3,6,2]}
Output:[1,2,3,4,5,6,7,8,9,10]
Explanation: Sorted merged array with preserved duplicates
Constraints
- The input arrays can have duplicate temperature readings.
- The total number of elements in both input arrays is between 2 and 1000.
Time: O(N) Space: O(1)
The optimal approach involves using the quick sort algorithm to sort each input array in O(n log n) time complexity, followed by a two-pointer technique to merge the sorted arrays in O(n) time complexity. The overall time complexity of this approach is O(n log n).
Run, Test & Submit Code
Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.
Solve on Interactive WorkspaceTested Solutions
No solution code is currently loaded.
Complete this code in the workspace editor.
