Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make All Elements Equal to 1

Try to solve the Minimum Operations to Make All Elements Equal to 1 problem.

Statement

You are given an array nums consisting of positive integers.

In one operation, you can select an index i such that 0≤i<0 \leq i < nums.length −1- 1 and replace either nums[i] or nums[i + 1] with the greatest common divisor of nums[i] and nums[i + 1].

Return the minimum number of operations required to make all elements in nums equal to 11. If it is impossible to make every element equal to 11, return −1-1.

Constraints:

  • 2≤2 \leq nums.length ≤50\leq 50

  • 1≤1 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make All Elements Equal to 1

Try to solve the Minimum Operations to Make All Elements Equal to 1 problem.

Statement

You are given an array nums consisting of positive integers.

In one operation, you can select an index i such that 0≤i<0 \leq i < nums.length −1- 1 and replace either nums[i] or nums[i + 1] with the greatest common divisor of nums[i] and nums[i + 1].

Return the minimum number of operations required to make all elements in nums equal to 11. If it is impossible to make every element equal to 11, return −1-1.

Constraints:

  • 2≤2 \leq nums.length ≤50\leq 50

  • 1≤1 \leq nums[i] ≤106\leq 10^6