commit ef6377bb9bbd8b9bcd6e390af70e03e53184fbf0
parent 3c45b200678617180f71f3e7f7cb6f0df68f0c95
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Sun, 2 Jun 2024 16:11:41 +0200
1 Random Problem
Diffstat:
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/Problems/1352.cpp b/Problems/1352.cpp
@@ -0,0 +1,16 @@
+class ProductOfNumbers {
+ vector<long long> prefix = {1};
+
+ public:
+ void add(int num) {
+ if (num == 0)
+ prefix = {1};
+ else
+ prefix.push_back(num * prefix.back());
+ }
+
+ int getProduct(int k) {
+ if (k >= prefix.size()) return 0;
+ return prefix.back() / prefix[prefix.size() - k - 1];
+ }
+};
diff --git a/README.md b/README.md
@@ -762,6 +762,7 @@ for solving problems.
| 1346 | Easy | [Check if N and Its Double Exist](Problems/1346.cpp) |
| 1347 | Medium | [Minimum Number of Steps to Make Two Strings Anagram](Problems/1347.cpp) |
| 1351 | Easy | [Count Negative Numbers in a Sorted Matrix](Problems/1351.cpp) |
+| 1352 | Medium | [Product of the Last K Numbers](Problems/1352.cpp) |
| 1356 | Easy | [Sort Integers by The Number of 1 Bits](Problems/1356.cpp) |
| 1357 | Medium | [Apply Discount Every n Orders](Problems/1357.cpp) |
| 1358 | Medium | [Number of Substrings Containing All Three Characters](Problems/1358.cpp) |