Given an array of elements. We can perform following operation only- Increase an array element. Cost of operation is the amount of increment made per array element. Now for a given H, we need to make any H ( not necessarily consecutive ) elements of array equal with minimum cost. E.g. N=6, H=4 2 3 5 6 4 4 changes to -> 4 4 5 6 4 4 Cost is ( 4-2 + 4-3 = 3 ) N=6, H=3 2 3 5 6 4 4 changes to -> 2 4 5 6 4 4 Cost is ( 4-3 = 1 ) Optimal complexity- O(N)
Be the first one to answer
Add answer anonymously...
Top Snapdeal Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app