Ctrl K

GCD Times LCM, Drop One

Medium
You are given an array of positive integers values. The score of an array is the greatest common divisor (GCD) of all its elements multiplied by their least common multiple (LCM). For a single number both the GCD and the LCM equal the number itself, and the score of an empty array is 0. You may remove at most one element from the array. Return the highest score you can get.
Example 1
values=[3, 6, 12] → 72

Keeping everything: GCD 3, LCM 12, score 36. Dropping 3 makes the GCD 6 and the LCM 12, for a score of 72, which is the best.

Example 2
values=[2, 3, 4] → 12

Keeping everything: GCD 1, LCM 12, score 12. Dropping 2 gives 1 · 12 = 12, dropping 3 gives 2 · 4 = 8, dropping 4 gives 1 · 6 = 6. The answer is 12.

Example 3
values=[7] → 49

For a single number both the GCD and the LCM are 7, so the score is 49. Dropping it leaves an empty array with score 0.

Constraints
  • 1 ≤ len(values) ≤ 100
  • 1 ≤ values[i] ≤ 10⁴
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Below a Bound MediumPhoto Frames of the Same Shape MediumSegments on a Chart MediumChunks With a Common Divisor MediumSegments With a Given GCD Medium
loading Python…
Input
values=[3, 6, 12]
Expected
72

Run checks the first 3 tests in your browser. Submit checks all 123 tests on the server, hidden ones included.