Given an array arr of size n>=1, you can choose any two consecutive positive elements arr[i], arr[i+1] for all 0<=i<n-1 and do the following operation, either replace arr[i] by arr[i]%arr[i+1] or arr[i+1]%arr[i] any number of times.
Find the minimum length of array you can make.
Eg:
Input: arr={1, 1, 2, 3}
Output: 1
Explanation: Choose i=1, replace 1 by 1%2=1, arr={1,1,3}
Choose i=1, replace 1 by 1%3=1,arr={1,1}
Choose i=0, replace 1 by 1%1=0, arr={0}
So minimum possible length is 1.
Input: arr={2,2,2,2}
Output: 2
Explanation: Choose i=0, replace 2 by 2%2=0, arr={0,2,2}
Choose i=1, replace 2 by 2%2=0,arr={0,0}
Can't choose 0 now!
So minimum possible length is 2.
Comments (2)


