Skip to content

Commit 4c68002

Browse files
authored
Improved task 1032
1 parent 92a7db7 commit 4c68002

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ implementation 'com.github.javadev:leetcode-in-kotlin:1.12'
17501750
| # | Title | Difficulty | Tag | Time, ms | Time, %
17511751
|------|----------------|-------------|-------------|----------|---------
17521752
| 1143 |[Longest Common Subsequence](src/main/kotlin/g1101_1200/s1143_longest_common_subsequence/Solution.kt)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_17_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming | 307 | 38.36
1753-
| 1032 |[Maximum Sum of Two Non-Overlapping Subarrays](src/main/kotlin/g1001_1100/s1032_stream_of_characters/StreamChecker.kt)| Hard | Array, String, Design, Trie, Data_Stream | 733 | 100.00
1753+
| 1032 |[Stream of Characters](src/main/kotlin/g1001_1100/s1032_stream_of_characters/StreamChecker.kt)| Hard | Array, String, Design, Trie, Data_Stream | 733 | 100.00
17541754
| 1031 |[Maximum Sum of Two Non-Overlapping Subarrays](src/main/kotlin/g1001_1100/s1031_maximum_sum_of_two_non_overlapping_subarrays/Solution.kt)| Medium | Array, Dynamic_Programming, Sliding_Window | 172 | 100.00
17551755
| 1030 |[Matrix Cells in Distance Order](src/main/kotlin/g1001_1100/s1030_matrix_cells_in_distance_order/Solution.kt)| Easy | Array, Math, Sorting, Matrix, Geometry | 426 | 100.00
17561756
| 1029 |[Two City Scheduling](src/main/kotlin/g1001_1100/s1029_two_city_scheduling/Solution.kt)| Medium | Array, Sorting, Greedy | 148 | 100.00
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
1031\. Maximum Sum of Two Non-Overlapping Subarrays
1+
1032\. Stream of Characters
22

3-
Medium
3+
Hard
44

5-
Given an integer array `nums` and two integers `firstLen` and `secondLen`, return _the maximum sum of elements in two non-overlapping **subarrays** with lengths_ `firstLen` _and_ `secondLen`.
5+
Design an algorithm that accepts a stream of characters and checks if a suffix of these characters is a string of a given array of strings `words`.
66

7-
The array with length `firstLen` could occur before or after the array with length `secondLen`, but they have to be non-overlapping.
7+
For example, if `words = ["abc", "xyz"]` and the stream added the four characters (one by one) `'a'`, `'x'`, `'y'`, and `'z'`, your algorithm should detect that the suffix `"xyz"` of the characters `"axyz"` matches `"xyz"` from `words`.
88

9-
A **subarray** is a **contiguous** part of an array.
9+
Implement the `StreamChecker` class:
1010

11-
**Example 1:**
12-
13-
**Input:** nums = [0,6,5,2,2,5,1,9,4], firstLen = 1, secondLen = 2
14-
15-
**Output:** 20
16-
17-
**Explanation:** One choice of subarrays is [9] with length 1, and [6,5] with length 2.
11+
* `StreamChecker(String[] words)` Initializes the object with the strings array `words`.
12+
* `boolean query(char letter)` Accepts a new character from the stream and returns `true` if any non-empty suffix from the stream forms a word that is in `words`.
1813

19-
**Example 2:**
20-
21-
**Input:** nums = [3,8,1,3,2,1,8,9,0], firstLen = 3, secondLen = 2
22-
23-
**Output:** 29
24-
25-
**Explanation:** One choice of subarrays is [3,8,1] with length 3, and [8,9] with length 2.
14+
**Example 1:**
2615

27-
**Example 3:**
16+
**Input** ["StreamChecker", "query", "query", "query", "query", "query", "query", "query", "query", "query", "query", "query", "query"] [[["cd", "f", "kl"]], ["a"], ["b"], ["c"], ["d"], ["e"], ["f"], ["g"], ["h"], ["i"], ["j"], ["k"], ["l"]]
2817

29-
**Input:** nums = [2,1,5,6,0,9,5,0,3,8], firstLen = 4, secondLen = 3
18+
**Output:** [null, false, false, false, true, false, true, false, false, false, false, false, true]
3019

31-
**Output:** 31
20+
**Explanation:**
3221

33-
**Explanation:** One choice of subarrays is [5,6,0,9] with length 4, and [0,3,8] with length 3.
22+
StreamChecker streamChecker = new StreamChecker(["cd", "f", "kl"]);
23+
streamChecker.query("a"); // return False
24+
streamChecker.query("b"); // return False
25+
streamChecker.query("c"); // return False
26+
streamChecker.query("d"); // return True, because 'cd' is in the wordlist
27+
streamChecker.query("e"); // return False
28+
streamChecker.query("f"); // return True, because 'f' is in the wordlist
29+
streamChecker.query("g"); // return False
30+
streamChecker.query("h"); // return False
31+
streamChecker.query("i"); // return False
32+
streamChecker.query("j"); // return False
33+
streamChecker.query("k"); // return False
34+
streamChecker.query("l"); // return True, because 'kl' is in the wordlist
3435

3536
**Constraints:**
3637

37-
* `1 <= firstLen, secondLen <= 1000`
38-
* `2 <= firstLen + secondLen <= 1000`
39-
* `firstLen + secondLen <= nums.length <= 1000`
40-
* `0 <= nums[i] <= 1000`
38+
* `1 <= words.length <= 2000`
39+
* `1 <= words[i].length <= 2000`
40+
* `words[i]` consists of lowercase English letters.
41+
* `letter` is a lowercase English letter.
42+
* At most <code>4 * 10<sup>4</sup></code> calls will be made to query.

0 commit comments

Comments
 (0)