Water Equalization Problem Statement

You are provided with an array ARR of positive integers. Each integer represents the number of liters of water in a bucket. The goal is to make the liters of water in every bucket equal.

You can perform the following operations any number of times:

  • Completely remove a bucket from the sequence.
  • Draw some amount of water from a bucket.

Determine the minimum number of liters of water that need to be removed to ensure all buckets contain the same amount of water.

Input:

The first line contains an integer ‘T’ representing the number of test cases. Each test case consists of: 
- A line with a single integer ‘N’, indicating the number of elements in the array ARR.
- A line containing ‘N’ space-separated integers representing the elements of ARR.

Output:

For each test case, output a single integer, representing the minimum liters of water to remove. Print each result on a new line.

Example:

Input:
N = 4, ARR = [1, 1, 2, 2]
Output:
2
Explanation:

Choosing to equalize all buckets to 1 liter, 1 liter needs to be removed from the third and fourth buckets, totaling 2 liters removed.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 2000
  • 1 <= ARR[i] <= 100

Where ‘T’ is the number of test cases, ‘N’ is the number of buckets, and ARR[i] is the amount of water in the i-th bucket. The time limit is 1 second.

AnswerBot
4mo

Given an array of water buckets, find the minimum liters of water to remove to make all buckets equal.

  • Iterate through the array to find the most common water level

  • Calculate the total liters needed to ...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Intern Interview Questions Asked at DE Shaw

Q. Validate Binary Search Tree (BST) You are given a binary tree with 'N' integer n...read more
Q. Candies Distribution Problem Statement Prateek is a kindergarten teacher with a ...read more
Q. Binary Ones Count Problem Develop a program to determine the number of '1's in t...read more
Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits