We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#!/bin/python3importmathimportosimportrandomimportreimportsysdefgcd(x,y):x,y=abs(x),abs(y)while(y):x,y=y,x%yreturnxdefgcdAr(a):iflen(a)==2:returngcd(a[0],a[1])returngcd(a[0],gcdAr(a[1:]))# Complete the maximumValue function below.defmaximumValue(a):l=len(a)mat=[[0]*lforiinrange(l)]matSum=[[0]*lforiinrange(l)]matMax=[[0]*lforiinrange(l)]ma=-float('inf')foriinrange(l):mat[i][i]=abs(a[i])matSum[i][i]=a[i]matMax[i][i]=a[i]foriinrange(l):forjinrange(i+1,l):mat[i][j]=gcd(a[j],mat[i][j-1])foriinrange(l):forjinrange(i+1,l):matSum[i][j]=matSum[i][j-1]+a[j]print(matSum)foriinrange(l):forjinrange(i+1,l):matMax[i][j]=max(matMax[i][j-1],a[j])print(matMax)foriinrange(l):forjinrange(i,l):f=mat[i][j]*(matSum[i][j]-matMax[i][j])iff>ma:ma=freturnmaif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')n=int(input())a=list(map(int,input().rstrip().split()))result=maximumValue(a)fptr.write(str(result)+'\n')fptr.close()
C++ solution
Getting RunTime Errors
can some one please explain me this problem ?
here is hackerrank the strange function solution
suggest some modifications for my code, as it is not passing all the test cases because of runtime error
here is problem solution in python java c++ and c programming. https://programs.programmingoneonone.com/2021/05/hackerrank-the-strange-function-problem-solution.html