Blackrock | DSA - Array sort with min cost

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2024-04-15Added By Anonymous
Source: Link
Company: BlackRock
Role: SDE-3 (inferred)
Stage: Interview (inferred)
Location: unknown
Year: unknown

Original Experience:
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