From 0f301f56c6d796eafce63348af8dca79a2dc8ad1 Mon Sep 17 00:00:00 2001 From: boafire <47714542+boafire@users.noreply.github.com> Date: Wed, 17 Jul 2019 23:04:30 -0400 Subject: [PATCH] Python solution for grumpyBookstoreOwner --- .../grumpyBookstoreOwner/grumpyBookstoreOwner.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenges/grumpyBookstoreOwner/grumpyBookstoreOwner.py diff --git a/challenges/grumpyBookstoreOwner/grumpyBookstoreOwner.py b/challenges/grumpyBookstoreOwner/grumpyBookstoreOwner.py new file mode 100644 index 0000000..9f82e7b --- /dev/null +++ b/challenges/grumpyBookstoreOwner/grumpyBookstoreOwner.py @@ -0,0 +1,10 @@ +def grumpyBookstoreOwner(customers, grumpy, X): + nongrumpsum = sum([customers[i] for i in range(len(customers)) if grumpy[i] != 1]) + customers = [customers[i] if grumpy[i] == 1 else 0 for i in range(len(customers))] + sumextra = maxextra = sum(customers[:X]) + for i in range(X, len(customers)): + sumextra += customers[i] - customers[i-X] + maxextra = max(maxextra, sumextra) + return maxextra + nongrumpsum + +assert grumpyBookstoreOwner([1,0,1,2,1,1,7,5], [0,1,0,1,0,1,0,1], 3)