aboutsummaryrefslogtreecommitdiff
path: root/challenge-325/ysth/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-325/ysth/python/ch-2.py')
-rw-r--r--challenge-325/ysth/python/ch-2.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-325/ysth/python/ch-2.py b/challenge-325/ysth/python/ch-2.py
new file mode 100644
index 0000000000..f151496925
--- /dev/null
+++ b/challenge-325/ysth/python/ch-2.py
@@ -0,0 +1,18 @@
+import sys
+import bisect
+
+prices = [int(value) for value in sys.argv[1:]]
+
+
+sale_prices = []
+seen_prices = []
+for price in reversed(prices):
+ seen_price_index = bisect.bisect_right(seen_prices, price)
+ discount = seen_prices[seen_price_index-1] if seen_price_index > 0 else 0
+ if seen_price_index == 0 or seen_prices[seen_price_index-1] != price:
+ seen_prices[seen_price_index:] = [price]
+ sale_prices.insert(0, price - discount)
+
+
+print("prices: ", prices)
+print("sale prices ", sale_prices)