Solutions for Maximize the number of toys that can be purchased

• @Zafir, submitted in Python 3, achived 100% score
``````# Complete the maximumToys function below.
def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count

``````
• @Zafir, submitted in Python 3, achived 100% score
``````# Complete the maximumToys function below.
def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count

``````
• @admin, submitted in Python 2, achived 100% score
``````def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count``````
• @admin, submitted in Python 2, achived 100% score
``````def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count``````
• @alexander, submitted in Python 2, achived 100% score
``````def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count``````
• @jacob, submitted in JavaScript, achived 5% score
``````function solve(prices,k)
{
prices.sort();
count=0;
for (let i=0;i<prices;i++)
{
if (i<=k)
{
count+=1;
k-=i;
}
else
{
break;
}
}
return count;
}``````
• @jacob, submitted in Python 3, achived 100% score
``````# Complete the maximumToys function below.
def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count

``````
• @jacob, submitted in Python 2, achived 100% score
``````def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count
``````
• @alexander, submitted in Python 2, achived 100% score
``````def solve(prices, k):
prices.sort()
count = 0
for i in prices:
if (i <= k):
count += 1
k -= i
else:
break
return count``````
• @jacob, submitted in JavaScript, achived 5% score
``````function solve(prices,k)
{
prices.sort();
count=0;
for (let i=0;i<prices;i++)
{
if (i<=k)
{
count+=1;
k-=i;
}
else
{
break;
}
}
return count;
}``````