Sorting: Window Sort You are given an array A of integers. Your task is to sort the array in windows of size K alternate
Posted: Thu Jul 14, 2022 2:17 pm
Sorting: Window Sort You are given an array A of integers. Your task is to sort the array in windows of size K alternately, in increasing and decreasing order respectively, such that: 1. Subarray A[O]…A[K−1] should be sorted in increasing order. 2. Subarray A[K]….A[2∗K−1] should be sorted in decreasing order, and so on. Function Description In the provided code snippet, implement the provided windowSort (...) method using the variables to print the array in sorted order as given in the problem. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of −404, which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains two integers N and K. The second line contains N space-separated integers A[i.
1>=N<=1031>=K<=N0>=A<=103 Output Format The output contains the window-wise sorted array arr. Explanation In the output array, the subarrays of size K should be sorted alternatively in increasing order and decreasing order, respectively. Subarray A[O]…A[K−1] should be sorted in increasing order: 1221 Subarray A[K]…A[2∗K−1] should be sorted in decreasing order: 1311 8 Subarray A[2K]…A[3K−1] should be sorted in increasing order: 34 After performing the above operations, we get A=[1,2,21,13,11,8,3,4].
1>=N<=1031>=K<=N0>=A<=103 Output Format The output contains the window-wise sorted array arr. Explanation In the output array, the subarrays of size K should be sorted alternatively in increasing order and decreasing order, respectively. Subarray A[O]…A[K−1] should be sorted in increasing order: 1221 Subarray A[K]…A[2∗K−1] should be sorted in decreasing order: 1311 8 Subarray A[2K]…A[3K−1] should be sorted in increasing order: 34 After performing the above operations, we get A=[1,2,21,13,11,8,3,4].