Leaderboard
Showing:
Sorting all array elements except one
Easy Accuracy: 63.64% Submissions: 833 Points: 2

Given an array A of positive integers, sort the array in ascending order such that element at index K in unsorted array stays unmoved and all other elements are sorted.

 

Example 1:

​Input : arr[ ] = {10, 4, 11, 7, 6, 20} 
        and K = 2
Output : 4 6 11 7 10 20
Explanation:
Sort an array except an index 2 So, 
4 6 11 7 10 20 


​Example 2:

Input : arr[ ] = {30, 20, 10} and K = 0
Output :  30 10 20 

 

Your Task:
This is a function problem. The input is already taken care of by the driver code. You only need to complete the function sortExceptK() that takes an array (arr), sizeOfArray (n), an integer K and return he sorted array except for the element at index K. The driver code takes care of the printing.

Expected Time Complexity: O(N*LOG(N)).
Expected Auxiliary Space: O(1).


Constraints:
1 ≤ N ≤ 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Sorting all array elements except one

Output Window