Skip to content

Commit ace9fba

Browse files
add skeleton for 1352
1 parent 1379124 commit ace9fba

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1352|[Product of the Last K Numbers](https://leetcode.com/problems/product-of-the-last-k-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1352.java) | |Medium|Array, Design|
1112
|1351|[Count Negative Numbers in a Sorted Matrix](https://leetcode.com/problems/count-negative-numbers-in-a-sorted-matrix/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1351.java) | |Easy|Array, Binary Search|
1213
|1349|[Maximum Students Taking Exam](https://leetcode.com/problems/maximum-students-taking-exam/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1349.java) | |Hard|Dynamic Programming|
1314
|1348|[Tweet Counts Per Frequency](https://leetcode.com/problems/tweet-counts-per-frequency/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1348.java) | |Medium|Design|
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.fishercoder.solutions;
2+
3+
/**
4+
* 1352. Product of the Last K Numbers
5+
*
6+
* Implement the class ProductOfNumbers that supports two methods:
7+
* 1. add(int num)
8+
* Adds the number num to the back of the current list of numbers.
9+
* 2. getProduct(int k)
10+
* Returns the product of the last k numbers in the current list.
11+
* You can assume that always the current list has at least k numbers.
12+
* At any time, the product of any contiguous sequence of numbers will fit into a single 32-bit integer without overflowing.
13+
*
14+
* Example:
15+
* Input
16+
* ["ProductOfNumbers","add","add","add","add","add","getProduct","getProduct","getProduct","add","getProduct"]
17+
* [[],[3],[0],[2],[5],[4],[2],[3],[4],[8],[2]]
18+
* Output
19+
* [null,null,null,null,null,null,20,40,0,null,32]
20+
* Explanation
21+
* ProductOfNumbers productOfNumbers = new ProductOfNumbers();
22+
* productOfNumbers.add(3); // [3]
23+
* productOfNumbers.add(0); // [3,0]
24+
* productOfNumbers.add(2); // [3,0,2]
25+
* productOfNumbers.add(5); // [3,0,2,5]
26+
* productOfNumbers.add(4); // [3,0,2,5,4]
27+
* productOfNumbers.getProduct(2); // return 20. The product of the last 2 numbers is 5 * 4 = 20
28+
* productOfNumbers.getProduct(3); // return 40. The product of the last 3 numbers is 2 * 5 * 4 = 40
29+
* productOfNumbers.getProduct(4); // return 0. The product of the last 4 numbers is 0 * 2 * 5 * 4 = 0
30+
* productOfNumbers.add(8); // [3,0,2,5,4,8]
31+
* productOfNumbers.getProduct(2); // return 32. The product of the last 2 numbers is 4 * 8 = 32
32+
*
33+
* Constraints:
34+
* There will be at most 40000 operations considering both add and getProduct.
35+
* 0 <= num <= 100
36+
* 1 <= k <= 40000
37+
* */
38+
public class _1352 {
39+
public static class Solution1 {
40+
public static class ProductOfNumbers {
41+
42+
public ProductOfNumbers() {
43+
44+
}
45+
46+
public void add(int num) {
47+
48+
}
49+
50+
public int getProduct(int k) {
51+
return -1;
52+
}
53+
}
54+
}
55+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.solutions._1352;
4+
import org.junit.BeforeClass;
5+
import org.junit.Test;
6+
7+
public class _1352Test {
8+
private static _1352.Solution1.ProductOfNumbers productOfNumbers;
9+
10+
@BeforeClass
11+
public static void setup() {
12+
productOfNumbers = new _1352.Solution1.ProductOfNumbers();
13+
}
14+
15+
@Test
16+
public void test1() {
17+
18+
}
19+
20+
}

0 commit comments

Comments
 (0)