Skip to content

Commit 09a7e84

Browse files
committed
Create README - LeetHub
1 parent 9f9f256 commit 09a7e84

File tree

1 file changed

+38
-0
lines changed
  • 2753-minimum-number-of-operations-to-make-all-array-elements-equal-to-1

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<h2><a href="https://leetcode.com/problems/minimum-number-of-operations-to-make-all-array-elements-equal-to-1">2753. Minimum Number of Operations to Make All Array Elements Equal to 1</a></h2><h3>Medium</h3><hr><p>You are given a <strong>0-indexed</strong>&nbsp;array <code>nums</code> consisiting of <strong>positive</strong> integers. You can do the following operation on the array <strong>any</strong> number of times:</p>
2+
3+
<ul>
4+
<li>Select an index <code>i</code> such that <code>0 &lt;= i &lt; n - 1</code> and replace either of&nbsp;<code>nums[i]</code> or <code>nums[i+1]</code> with their gcd value.</li>
5+
</ul>
6+
7+
<p>Return <em>the <strong>minimum</strong> number of operations to make all elements of </em><code>nums</code><em> equal to </em><code>1</code>. If it is impossible, return <code>-1</code>.</p>
8+
9+
<p>The gcd of two integers is the greatest common divisor of the two integers.</p>
10+
11+
<p>&nbsp;</p>
12+
<p><strong class="example">Example 1:</strong></p>
13+
14+
<pre>
15+
<strong>Input:</strong> nums = [2,6,3,4]
16+
<strong>Output:</strong> 4
17+
<strong>Explanation:</strong> We can do the following operations:
18+
- Choose index i = 2 and replace nums[2] with gcd(3,4) = 1. Now we have nums = [2,6,1,4].
19+
- Choose index i = 1 and replace nums[1] with gcd(6,1) = 1. Now we have nums = [2,1,1,4].
20+
- Choose index i = 0 and replace nums[0] with gcd(2,1) = 1. Now we have nums = [1,1,1,4].
21+
- Choose index i = 2 and replace nums[3] with gcd(1,4) = 1. Now we have nums = [1,1,1,1].
22+
</pre>
23+
24+
<p><strong class="example">Example 2:</strong></p>
25+
26+
<pre>
27+
<strong>Input:</strong> nums = [2,10,6,14]
28+
<strong>Output:</strong> -1
29+
<strong>Explanation:</strong> It can be shown that it is impossible to make all the elements equal to 1.
30+
</pre>
31+
32+
<p>&nbsp;</p>
33+
<p><strong>Constraints:</strong></p>
34+
35+
<ul>
36+
<li><code>2 &lt;= nums.length &lt;= 50</code></li>
37+
<li><code>1 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
38+
</ul>

0 commit comments

Comments
 (0)