Your Dashboard
Interview Coaching
Learn
System Design
ML System Design
Code
Behavioral
Salary Negotiation
Interview Guides
Search
⌘K
Get Premium
Leetcode 2654. Minimum Number of Operations to Make All Array Elements Equal to 1
You may replace either number of any adjacent pair with their gcd; compute the minimum operations to make every element 1 (or return -1 if impossible). Key idea: if any element is 1 the answer is n - count(1); if gcd(all) > 1 it's impossible; otherwise find the shortest subarray whose gcd is 1 and the minimum operations = n + (subarray length) - 2.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.