Blackrock | DSA - Array sort with min cost

Anonymous User
705
Apr 15, 2024

Can someone please help in solving the below question. It was asked in Blackrock interview for SDE-3.
We have to sort the array with minimum cost

Input: [1,2,3,4,6,5]
Output: 1
Explaination: arr[4] is 6 which can be changed to either 4(=arr[3]) or 5 (=arr[5]) . But min cost will be if it is changed to 5 (Math.abs(6-5) = 1) which will make the final array as [1,2,3,4,5,5]

Comments (5)