Given an array of elements, you can only increase array elements. The cost of an operation is the amount of increment made per array element. For a given H, make any H elements of the array equal with minimum cost. For example, if N=6, H=4 and the array is [2, 3, 5, 6, 4, 4], changing it to [4, 4, 5, 6, 4, 4] has a cost of (4-2 + 4-3 = 3). If N=6, H=3 and the array is [2, 3, 5, 6, 4, 4], changing it to [2, 4, 5, 6, 4, 4] has a cost of (4-3 = 1). What is the optimal O(N) solution?

AnswerBot
1mo
Minimize cost to make H elements of an array equal by only increasing their values.
Identify the target value H that elements should be increased to.
Calculate the cost for each element that needs to be...read more
Help your peers!
Add answer anonymously...
Snapdeal Software Developer interview questions & answers
A Software Developer was asked Q. Given two linked lists that merge at a point, find the merging point.
A Software Developer was asked Q. Given an M x N matrix, how many rectangles are there?
A Software Developer was asked Q. Find a four-digit number in the form aabb that is a perfect square.
Popular interview questions of Software Developer
A Software Developer was asked Q1. Given two linked lists that merge at a point, find the merging point.
A Software Developer was asked Q2. Given an M x N matrix, how many rectangles are there?
A Software Developer was asked Q3. Find a four-digit number in the form aabb that is a perfect square.
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

