Search
⌘K

Leetcode 2197. Replace Non-Coprime Numbers in Array

Repeatedly scan the array and whenever two adjacent numbers have GCD>1 replace them with their LCM, continuing until no adjacent non-coprime pairs remain; return the final array. The challenge is to efficiently handle cascading merges (e.g., with a stack and gcd/lcm operations) for up to 1e5 elements (nums[i] ≤ 1e5, final values ≤ 1e8).


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.