Skip to content

Commit 5f00ef6

Browse files
committed
Added task 3716
1 parent 374444e commit 5f00ef6

File tree

15 files changed

+203
-31
lines changed

15 files changed

+203
-31
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,7 @@
20882088

20892089
| # | Title | Difficulty | Tag | Time, ms | Time, %
20902090
|------|----------------|-------------|-------------|----------|---------
2091+
| 3716 |[Find Churn Risk Customers](src/main/kotlin/g3701_3800/s3716_find_churn_risk_customers)| Medium | Database | 256 | 96.87
20912092
| 3715 |[Sum of Perfect Square Ancestors](src/main/kotlin/g3701_3800/s3715_sum_of_perfect_square_ancestors)| Hard | Array, Hash_Table, Math, Depth_First_Search, Tree, Counting, Number_Theory, Weekly_Contest_471 | 148 | 100.00
20922093
| 3714 |[Longest Balanced Substring II](src/main/kotlin/g3701_3800/s3714_longest_balanced_substring_ii)| Medium | String, Hash_Table, Prefix_Sum, Weekly_Contest_471 | 194 | 100.00
20932094
| 3713 |[Longest Balanced Substring I](src/main/kotlin/g3701_3800/s3713_longest_balanced_substring_i)| Medium | String, Hash_Table, Counting, Enumeration, Weekly_Contest_471 | 35 | 100.00
@@ -2867,7 +2868,7 @@
28672868
| 2730 |[Find the Longest Semi-Repetitive Substring](src/main/kotlin/g2701_2800/s2730_find_the_longest_semi_repetitive_substring)| Medium | String, Sliding_Window | 251 | 84.62
28682869
| 2729 |[Check if The Number is Fascinating](src/main/kotlin/g2701_2800/s2729_check_if_the_number_is_fascinating)| Easy | Hash_Table, Math | 131 | 100.00
28692870
| 2727 |[Is Object Empty](src/main/kotlin/g2701_2800/s2727_is_object_empty)| Easy || 49 | 98.24
2870-
| 2726 |[Calculator with Method Chaining](src/main/kotlin/g2701_2800/s2726_calculator_with_method_chaining)| Easy || 43 | 99.15
2871+
| 2726 |[Calculator with Method Chaining](src/main/kotlin/g2701_2800/s2726_calculator_with_method_chaining)| Easy || 39 | 99.67
28712872
| 2725 |[Interval Cancellation](src/main/kotlin/g2701_2800/s2725_interval_cancellation)| Easy || 51 | 98.87
28722873
| 2724 |[Sort By](src/main/kotlin/g2701_2800/s2724_sort_by)| Easy || 132 | 96.70
28732874
| 2723 |[Add Two Promises](src/main/kotlin/g2701_2800/s2723_add_two_promises)| Easy || 56 | 97.63
@@ -2886,15 +2887,15 @@
28862887
| 2708 |[Maximum Strength of a Group](src/main/kotlin/g2701_2800/s2708_maximum_strength_of_a_group)| Medium | Array, Sorting, Greedy, Backtracking | 183 | 100.00
28872888
| 2707 |[Extra Characters in a String](src/main/kotlin/g2701_2800/s2707_extra_characters_in_a_string)| Medium | Array, String, Hash_Table, Dynamic_Programming, Trie | 276 | 85.71
28882889
| 2706 |[Buy Two Chocolates](src/main/kotlin/g2701_2800/s2706_buy_two_chocolates)| Easy | Array, Sorting | 187 | 96.43
2889-
| 2705 |[Compact Object](src/main/kotlin/g2701_2800/s2705_compact_object)| Medium || 78 | 99.38
2890+
| 2705 |[Compact Object](src/main/kotlin/g2701_2800/s2705_compact_object)| Medium || 80 | 88.30
28902891
| 2704 |[To Be Or Not To Be](src/main/kotlin/g2701_2800/s2704_to_be_or_not_to_be)| Easy || 49 | 97.88
28912892
| 2703 |[Return Length of Arguments Passed](src/main/kotlin/g2701_2800/s2703_return_length_of_arguments_passed)| Easy || 47 | 98.59
28922893
| 2699 |[Modify Graph Edge Weights](src/main/kotlin/g2601_2700/s2699_modify_graph_edge_weights)| Hard | Heap_Priority_Queue, Graph, Shortest_Path | 1592 | 40.00
28932894
| 2698 |[Find the Punishment Number of an Integer](src/main/kotlin/g2601_2700/s2698_find_the_punishment_number_of_an_integer)| Medium | Math, Backtracking | 133 | 100.00
28942895
| 2697 |[Lexicographically Smallest Palindrome](src/main/kotlin/g2601_2700/s2697_lexicographically_smallest_palindrome)| Easy | String, Two_Pointers | 267 | 100.00
28952896
| 2696 |[Minimum String Length After Removing Substrings](src/main/kotlin/g2601_2700/s2696_minimum_string_length_after_removing_substrings)| Easy | String, Stack, Simulation | 185 | 100.00
28962897
| 2695 |[Array Wrapper](src/main/kotlin/g2601_2700/s2695_array_wrapper)| Easy || 40 | 100.00
2897-
| 2694 |[Event Emitter](src/main/kotlin/g2601_2700/s2694_event_emitter)| Medium || 45 | 99.58
2898+
| 2694 |[Event Emitter](src/main/kotlin/g2601_2700/s2694_event_emitter)| Medium || 50 | 90.72
28982899
| 2693 |[Call Function with Custom Context](src/main/kotlin/g2601_2700/s2693_call_function_with_custom_context)| Medium | Array, Dynamic_Programming, Matrix | 51 | 97.92
28992900
| 2685 |[Count the Number of Complete Components](src/main/kotlin/g2601_2700/s2685_count_the_number_of_complete_components)| Medium | Array, Dynamic_Programming, Depth_First_Search, Breadth_First_Search, Matrix, Graph | 436 | 100.00
29002901
| 2684 |[Maximum Number of Moves in a Grid](src/main/kotlin/g2601_2700/s2684_maximum_number_of_moves_in_a_grid)| Medium | Array, Dynamic_Programming, Matrix | 509 | 100.00

src/main/kotlin/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/readme.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,36 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
1313

1414
**Example 1:**
1515

16-
![](https://assets.leetcode.com/uploads/2021/11/09/flatten11.jpg)
16+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten11.jpg)
1717

1818
**Input:** head = [1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
1919

2020
**Output:** [1,2,3,7,8,11,12,9,10,4,5,6]
2121

22-
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://assets.leetcode.com/uploads/2021/11/09/flatten12.jpg)
22+
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten12.jpg)
2323

2424
**Example 2:**
2525

26-
![](https://assets.leetcode.com/uploads/2021/11/09/flatten2.1jpg)
26+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/flatten21.jpg)
2727

2828
**Input:** head = [1,2,null,3]
2929

3030
**Output:** [1,3,2]
3131

32-
**Explanation:** The multilevel linked list in the input is shown. After flattening the multilevel linked list it becomes: ![](https://assets.leetcode.com/uploads/2021/11/24/list.jpg)
32+
**Explanation:**
33+
34+
The multilevel linked list in the input is shown.
35+
After flattening the multilevel linked list it becomes:
36+
37+
![](https://leetcode-images.github.io/g0401_0500/s0430_flatten_a_multilevel_doubly_linked_list/list.jpg)
3338

3439
**Example 3:**
3540

3641
**Input:** head = []
3742

3843
**Output:** []
3944

40-
**Explanation:** There could be empty list in the input.
45+
**Explanation:** There could be empty list in the input.
4146

4247
**Constraints:**
4348

@@ -48,19 +53,29 @@ Return _the_ `head` _of the flattened list. The nodes in the list must have **al
4853

4954
We use the multilevel linked list from **Example 1** above:
5055

51-
1---2---3---4---5---6--NULL \| 7---8---9---10--NULL \| 11--12--NULL
56+
1---2---3---4---5---6--NULL
57+
|
58+
7---8---9---10--NULL
59+
|
60+
11--12--NULL
5261

5362
The serialization of each level is as follows:
5463

55-
[1,2,3,4,5,6,null] [7,8,9,10,null] [11,12,null]
64+
[1,2,3,4,5,6,null]
65+
[7,8,9,10,null]
66+
[11,12,null]
5667

5768
To serialize all levels together, we will add nulls in each level to signify no node connects to the upper node of the previous level. The serialization becomes:
5869

59-
[1, 2, 3, 4, 5, 6, null] \| [null, null, 7, 8, 9, 10, null] \| [ null, 11, 12, null]
70+
[1, 2, 3, 4, 5, 6, null]
71+
|
72+
[null, null, 7, 8, 9, 10, null]
73+
|
74+
[ null, 11, 12, null]
6075

6176
Merging the serialization of each level and removing trailing nulls we obtain:
6277

63-
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
78+
[1,2,3,4,5,6,null,null,null,7,8,9,10,null,null,11,12]
6479

6580
## Solution
6681

src/main/kotlin/g2601_2700/s2619_array_prototype_last/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ declare global {
3939
}
4040

4141
Array.prototype.last = function () { //NOSONAR
42-
return this.length !== 0 ? this[this.length - 1] : -1
42+
return this.length !== 0 ? this[this.length - 1] : -1 //NOSONAR
4343
}
4444

4545
/*
4646
* const arr = [1, 2, 3];
4747
* arr.last(); // 3
4848
*/
4949

50-
export {}
50+
export {} //NOSONAR
5151
```

src/main/kotlin/g2601_2700/s2624_snail_traversal/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ Array.prototype.snail = function (rowsCount: number, colsCount: number): number[
7373
* arr.snail(1,4); // [[1,2,3,4]]
7474
*/
7575

76-
export {}
76+
export {} //NOSONAR
7777
```

src/main/kotlin/g2601_2700/s2626_array_reduce_transformation/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type Fn = (accum: number, curr: number) => number
7070

7171
function reduce(nums: number[], fn: Fn, init: number): number {
7272
let accumulator = init
73-
nums.forEach((num) => {
73+
nums.forEach((num) => { //NOSONAR
7474
accumulator = fn(accumulator, num)
7575
})
7676
return accumulator

src/main/kotlin/g2601_2700/s2630_memoize_ii/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function memoize(fn: Fn): Fn {
104104

105105
let value = fn(...args)
106106

107-
currentCache.set(args[args.length - 1], value)
107+
currentCache.set(args[args.length - 1], value) //NOSONAR
108108
return value
109109
}
110110
}

src/main/kotlin/g2601_2700/s2631_group_by/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ Array.prototype.groupBy = function <T>(fn: (item: T) => string) { //NOSONAR
120120
* [1,2,3].groupBy(String) // {"1":[1],"2":[2],"3":[3]}
121121
*/
122122

123-
export {}
123+
export {} //NOSONAR
124124
```

src/main/kotlin/g2601_2700/s2693_call_function_with_custom_context/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,5 @@ Function.prototype.callPolyfill = function (context, ...args): any { //NOSONAR
7474
* increment.callPolyfill({count: 1}); // 2
7575
*/
7676

77-
export {}
77+
export {} //NOSONAR
7878
```

src/main/kotlin/g2601_2700/s2694_event_emitter/readme.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,34 @@ type Subscription = {
8888
}
8989

9090
class EventEmitter {
91-
subs: Record<string, Callback[]> = {}
91+
eventMap: Map<string, Set<Callback>>
92+
93+
constructor() {
94+
this.eventMap = new Map()
95+
}
9296

9397
subscribe(eventName: string, callback: Callback): Subscription {
94-
if (!this.subs[eventName]) this.subs[eventName] = []
95-
const idx = this.subs[eventName].push(callback) - 1
98+
if (this.eventMap.has(eventName)) {
99+
const set = this.eventMap.get(eventName)!
100+
set.add(callback)
101+
this.eventMap.set(eventName, set)
102+
} else {
103+
const set = new Set<Callback>()
104+
set.add(callback)
105+
this.eventMap.set(eventName, set)
106+
}
107+
96108
return {
97-
unsubscribe: () => this.subs[eventName].splice(idx, 1),
109+
unsubscribe: () => {
110+
this.eventMap.get(eventName).delete(callback)
111+
},
98112
}
99113
}
100114

101115
emit(eventName: string, args: any[] = []): any[] {
102-
return this.subs[eventName]?.map((callback) => callback(...args)) || []
116+
const res = []
117+
this.eventMap.get(eventName)?.forEach((cb) => res.push(cb(...args))) //NOSONAR
118+
return res
103119
}
104120
}
105121

src/main/kotlin/g2701_2800/s2705_compact_object/readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Obj = Record<any, any>
4646
function compactObject(obj: Obj): Obj {
4747
if (Array.isArray(obj)) {
4848
let retArr = []
49-
obj.forEach((e, idx) => {
49+
obj.forEach((e, idx) => { //NOSONAR
5050
if (e) {
5151
retArr.push(compactObject(e))
5252
}

0 commit comments

Comments
 (0)