0% found this document useful (0 votes)
11 views

Sorting Sheet

Uploaded by

beetlejuiceezz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Sorting Sheet

Uploaded by

beetlejuiceezz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sorting assignment

(1) Minimum swaps to make two arrays consisting


unique elements identical

Given two arrays that have the same values but in a different order and
having no duplicate elements in it, we need to make a second array the
same as a first array using the minimum number of swaps.
Examples:
Input : arrA[] = {3, 6, 4, 8},
arrB[] = {4, 6, 8, 3}
Output : 2

(2) K-th smallest element after removing some integers


from natural numbers
Given an array arr[] of size ‘n’ and a positive integer k. Consider series of
natural numbers and remove arr[0], arr[1], arr[2], …, arr[p] from it. Now the
task is to find k-th smallest number in the remaining set of natural numbers. If
no such number exists print “-1”.

Examples :
Input : arr[] = { 1 } and k = 1.
Output: 2
Input : arr[] = {1, 3}, k = 4.
Output : 6
(3) Choose k array elements such that difference of
maximum and minimum is minimized

Given an array of n integers and a positive number k. We are allowed to


take any k integers from the given array. The task is to find the
minimum possible value of the difference between maximum and
minimum of K numbers.
Examples:
Input : arr[] = {10, 100, 300, 200, 1000, 20, 30}
k=3
Output : 20

(4) Sort an array after applying the given equation


We have an integer array that is sorted in ascending order. We also have 3
integers A, B and C. We need to apply A*x*x + B*x + C for each element x in
the array and sort the modified array.
Example:
Input : arr[] = {-1, 0, 1, 2, 3, 4}
A = -1, B = 2, C = -1
Output : {-9, -4, -4, -1, -1, 0}

You might also like