Tap here to switch tabs
Problem
Submissions

Problem: Removing Minimum Number of Magic Beans

Try to solve the 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 contained in a bag.

You want to remove beans from the bags such that every remaining non empty bag contains the exact same number of magic beans. You can remove any number of beans from any bag, including emptying it completely, but you cannot add beans to any bag.

Return the minimum total number of magic beans that must be removed.

Constraints:

  • 1≤1 \leq beans.length ≤105\leq 10^5

  • 1≤1 \leq beans[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Removing Minimum Number of Magic Beans

Try to solve the 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 contained in a bag.

You want to remove beans from the bags such that every remaining non empty bag contains the exact same number of magic beans. You can remove any number of beans from any bag, including emptying it completely, but you cannot add beans to any bag.

Return the minimum total number of magic beans that must be removed.

Constraints:

  • 1≤1 \leq beans.length ≤105\leq 10^5

  • 1≤1 \leq beans[i] ≤105\leq 10^5