Find Maximum Possible GCD

Problem Overview

  • Given R and an array A, you may replace at most one element with any X in [1, R]; find the maximum possible GCD of the array.
  • Input: N, R, A with 2 ≤ N ≤ 1e5, 1 ≤ R ≤ 1e5, 1 ≤ Ai ≤ 1e5. Output: the maximum GCD after the optional change.
  • Applies to optimizing a shared factor in data or configurations with a single bounded edit.
  • From Barclay interviews; a coding interview problem and interview question on arrays and number theory.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: