LeetCode Courses 3927. Minimize Array Sum Using Divisible Replacements
LeetCode

3927. Minimize Array Sum Using Divisible Replacements

We iterate from a brute-force pair check through a divisor sieve, then drop the constant factor with numpy. Inverting the question into a sieve avoids checking every pair.

1 chapter Intermediate Written walk-through Updated 15 May 2026 Phil · @FirnoxGames
Best value · subscribe
£4.99 /mo £8.99 ★ FOUNDING MEMBER -44%
or £49/yr · cancel any time
Unlocks this course and everything else in our catalogue.
or just this one
£1 · yours forever

What you'll learn

🔒 3927. Minimize Array Sum Using Divisible Replacements 📖 19 min read

We iterate from a brute-force pair check through a divisor sieve, then drop the constant factor with numpy. Inverting the question into a sieve avoids checking every pair.

In this chapter
  1. Problem
  2. Brute force
  3. Sorting
  4. Sieving
  5. Optimising
  6. Going further
  7. Numpy
Subscribe or buy to unlock.

Problem

You are given an integer array nums.

You can perform the following operation any number of times:

  • Choose two indices a and b such that nums[a] % nums[b] == 0.
  • Replace nums[a] with nums[b].

Return the minimum possible sum of the array after performing any number of operations.

Included with this course
📖Written version of every chapter