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...
Snapdeal Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter