Skip to content

Practice Removing Minimum Number of Magic Beans

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2171
LeetCode Problem

Removing Minimum Number of Magic Beans

Problem Statement

You are given an array of positive integers beans, where each integer represents the number of magic beans found in a particular magic bag. Remove any number of beans (possibly none) from each bag such that the number of beans in each remaining non-empty bag (still containing at least one bean) is equal. Once a bean has been removed from a bag, you are not allowed to return it to any of the bags. Return the minimum number of magic beans that you have to remove.

Source: Removing Minimum Number of Magic Beans on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
beans = [4,1,6,5]
Output
4

# Example 2

Input
beans = [2,10,3,2]
Output
7

Constraints

1 <= beans.length <= 10^5
1 <= beans[i] <= 10^5

Related LeetCode Problems

Practice more problems similar to Removing Minimum Number of Magic Beans.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.