← Back to challenges

Souvenir Shop

PythonHardloopsarraysalgorithms

Instructions

On a vacation abroad, you see a souvenir shop and decide to head inside. There are snow globes, postcards, fridge magnets and all the other goodies you'd typically find.

Given a list of prices of things in the store and the amount of money you have, return the maximum number of items you could possibly buy.

Examples

maximum_items(["$1", "$1", "$2"], "$3") ➞ 2

maximum_items(["$10", "$7", "$2", "$60"], "$20") ➞ 3

maximum_items(["$15", "$5", "$30", "$30", "$10"], "$2") ➞ "Not enough funds!"

Notes

  • If you cannot afford anything, return "Not enough funds!"
  • Prices will be whole numbers.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.