Practice Replace Non-Coprime Numbers in Array
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Repeatedly replace two adjacent nums values having gcd greater than 1 with their least common multiple. Stop only when no such pair remains and return the resulting array. Any choice order yields the same final array, whose values are guaranteed not to exceed 10^8.
Source: Replace Non-Coprime Numbers in Array on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [6,4,3,2,7,6,2]
Output
[12,7,6]
# Example 2
Input
nums = [2,2,1,1,3,3,3]
Output
[2,1,1,3]
Constraints
1 <= nums.length <= 10^5
1 <= nums[i] <= 10^5
The test cases are generated such that the values in the final array are less than or equal to 10^8.
Related LeetCode Problems
Practice more problems similar to Replace Non-Coprime Numbers in Array.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.