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.
if curInd == len(arr):
if curresult%101 ==0:
return([True,expr])
else:
return([False,""])
resultTillnow=curresult
expTillnow=expr
for op in operators:
val2=arr[curInd]
if op=="ADD":
result=resultTillnow+val2
oper="+"
elif op=="MUL":
result=resultTillnow*val2
oper="*"
else:
result=resultTillnow-val2
oper="-"
nexpr=expTillnow+oper+str(val2)
stat,e=getexpression(arr,operators,curInd+1,result,nexpr)
if stat:
return([stat,e])
return([False,""])
def arithmeticExpressions(arr):
operators=['ADD','MUL','SUB']
stat,expr = getexpression(arr,operators,1,arr[0],str(arr[0]))
if stat:
return expr
tat:
return(expr)
return exprelse:
return("")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Arithmetic Expressions
You are viewing a single comment's thread. Return to all comments →
Hi, Can someone tell what is the issue with this code.I get
RunTimeError for 7th test case
. Its not TLE Errordef getexpression(arr,operators,curInd,curresult,expr):
resultTillnow=curresult
def arithmeticExpressions(arr):