You are viewing a single comment's thread. Return to all comments →
PARTIAL BRUTE FORCE SOLUTION FOR 10.5 POINTS 30 PERCENT FIRST SUBTASK
FIND ALL POSSIBLE SUBARRAYS AND AND APPLY THE FUNCTION DEFINITION AS PER QUESTION.
from math import gcd def func1(a1,b1): return gcd(a1,b1) def func(a,n): gcd1=a[0] for i in range(1,n): gcd1=func1(gcd1,a[i]) sum1=0 maxi=max(a) for i in range(n): sum1+=a[i] ans=gcd1*(sum1-maxi) return ans n=int(input()) a=list(map(int,input().split())) ans=-1 for i in range(n): for j in range(i,n): ans=max(ans,func(a[i:j+1],j-i+1)) print(ans)
github:- https://github.com/anirudhkannanvp/HACKERRANK
FOR ANY QUERIES MSG ME ON HACKERRANK OR GITHUB
Seems like cookies are disabled on this browser, please enable them to open this website
The Strange Function
You are viewing a single comment's thread. Return to all comments →
PARTIAL BRUTE FORCE SOLUTION FOR 10.5 POINTS 30 PERCENT FIRST SUBTASK
FIND ALL POSSIBLE SUBARRAYS AND AND APPLY THE FUNCTION DEFINITION AS PER QUESTION.
github:- https://github.com/anirudhkannanvp/HACKERRANK
FOR ANY QUERIES MSG ME ON HACKERRANK OR GITHUB