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.
here is python3 solution to the problem
sol1: by taking an empty list
def getMoneySpent(keyboards, drives, b):
l=[]
for i in keyboards:
for j in drives:
if i+j<=b:
l.append(i+j)
if not l:
return -1
else:
return max(l)
`
sol2: since list might end up taking too much storage
def getMoneySpent(keyboards, drives, b):
spent=-1
for i in keyboards:
for j in drives:
total=i+j
if total<=b:
spent= max(spent,total)
return spent
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Electronics Shop
You are viewing a single comment's thread. Return to all comments →
here is python3 solution to the problem sol1: by taking an empty list def getMoneySpent(keyboards, drives, b): l=[] for i in keyboards: for j in drives: if i+j<=b: l.append(i+j) if not l: return -1 else:
return max(l) ` sol2: since list might end up taking too much storage def getMoneySpent(keyboards, drives, b): spent=-1 for i in keyboards: for j in drives: total=i+j if total<=b: spent= max(spent,total) return spent