Skip to content

Commit 3395475

Browse files
authored
Added tasks 73-78
1 parent 511d99e commit 3395475

File tree

6 files changed

+340
-0
lines changed

6 files changed

+340
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
|-|-|-|-|-|-
104104
| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/ts/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 45 | 98.05
105105
| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54
106+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
106107

107108
#### Day 2 Binary Search
108109

@@ -146,6 +147,7 @@
146147

147148
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
148149
|-|-|-|-|-|-
150+
| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n*2^n) | 50 | 94.61
149151

150152
#### Day 10 Recursion Backtracking
151153

@@ -259,6 +261,7 @@
259261

260262
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
261263
|-|-|-|-|-|-
264+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
262265

263266
#### Day 9
264267

@@ -919,6 +922,7 @@
919922

920923
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
921924
|-|-|-|-|-|-
925+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
922926
| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 43 | 98.54
923927

924928
#### Day 9 Binary Search Tree
@@ -952,6 +956,7 @@
952956
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
953957
|-|-|-|-|-|-
954958
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 65 | 90.77
959+
| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 82 | 82.17
955960

956961
#### Day 15 Tree
957962

@@ -1016,6 +1021,7 @@
10161021
|-|-|-|-|-|-
10171022
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 54 | 91.72
10181023
| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 58 | 91.95
1024+
| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41
10191025
| 0041 |[First Missing Positive](src/main/ts/g0001_0100/s0041_first_missing_positive)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 55 | 98.51
10201026

10211027
#### Udemy Two Pointers
@@ -1040,7 +1046,9 @@
10401046

10411047
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10421048
|-|-|-|-|-|-
1049+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
10431050
| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 45 | 95.31
1051+
| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m*n)_Space_O(1) | 61 | 97.66
10441052
| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06
10451053

10461054
#### Udemy Linked List
@@ -1083,6 +1091,7 @@
10831091
|-|-|-|-|-|-
10841092
| 0022 |[Generate Parentheses](src/main/ts/g0001_0100/s0022_generate_parentheses)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 60 | 62.03
10851093
| 0039 |[Combination Sum](src/main/ts/g0001_0100/s0039_combination_sum)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 65 | 86.86
1094+
| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Big_O_Time_O(2^n)_Space_O(n*2^n) | 50 | 94.61
10861095
| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 52 | 79.11
10871096
| 0046 |[Permutations](src/main/ts/g0001_0100/s0046_permutations)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n*n!)_Space_O(n+n!) | 56 | 96.26
10881097

@@ -1124,6 +1133,7 @@
11241133

11251134
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11261135
|-|-|-|-|-|-
1136+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
11271137

11281138
#### Day 6 String
11291139

@@ -1184,6 +1194,7 @@
11841194

11851195
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11861196
|-|-|-|-|-|-
1197+
| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41
11871198
| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 84 | 92.06
11881199

11891200
#### Day 3 Array
@@ -1303,6 +1314,11 @@
13031314
| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 69 | 96.69
13041315
| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 68 | 86.71
13051316
| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n*sums)_Space_O(n*sums) | 91 | 74.38
1317+
| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n*2^n) | 50 | 94.61
1318+
| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Big_O_Time_O(s.length())_Space_O(1) | 82 | 82.17
1319+
| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_2_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 43 | 97.41
1320+
| 0074 |[Search a 2D Matrix](src/main/ts/g0001_0100/s0074_search_a_2d_matrix)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Data_Structure_I_Day_5_Array, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_8, Level_2_Day_8_Binary_Search, Udemy_2D_Arrays/Matrix, Big_O_Time_O(endRow+endCol)_Space_O(1) | 45 | 96.82
1321+
| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Udemy_2D_Arrays/Matrix, Big_O_Time_O(m*n)_Space_O(1) | 61 | 97.66
13061322
| 0072 |[Edit Distance](src/main/ts/g0001_0100/s0072_edit_distance)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 68 | 95.20
13071323
| 0070 |[Climbing Stairs](src/main/ts/g0001_0100/s0070_climbing_stairs)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 44 | 94.58
13081324
| 0064 |[Minimum Path Sum](src/main/ts/g0001_0100/s0064_minimum_path_sum)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Big_O_Time_O(m*n)_Space_O(m*n) | 48 | 99.67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 73\. Set Matrix Zeroes
5+
6+
Medium
7+
8+
Given an `m x n` integer matrix `matrix`, if an element is `0`, set its entire row and column to `0`'s, and return _the matrix_.
9+
10+
You must do it [in place](https://en.wikipedia.org/wiki/In-place_algorithm).
11+
12+
**Example 1:**
13+
14+
![](https://assets.leetcode.com/uploads/2020/08/17/mat1.jpg)
15+
16+
**Input:** matrix = \[\[1,1,1],[1,0,1],[1,1,1]]
17+
18+
**Output:** [[1,0,1],[0,0,0],[1,0,1]]
19+
20+
**Example 2:**
21+
22+
![](https://assets.leetcode.com/uploads/2020/08/17/mat2.jpg)
23+
24+
**Input:** matrix = \[\[0,1,2,0],[3,4,5,2],[1,3,1,5]]
25+
26+
**Output:** [[0,0,0,0],[0,4,5,0],[0,3,1,0]]
27+
28+
**Constraints:**
29+
30+
* `m == matrix.length`
31+
* `n == matrix[0].length`
32+
* `1 <= m, n <= 200`
33+
* <code>-2<sup>31</sup> <= matrix[i][j] <= 2<sup>31</sup> - 1</code>
34+
35+
**Follow up:**
36+
37+
* A straightforward solution using `O(mn)` space is probably a bad idea.
38+
* A simple improvement uses `O(m + n)` space, but still not the best solution.
39+
* Could you devise a constant space solution?
40+
41+
## Solution
42+
43+
```typescript
44+
/*
45+
Do not return anything, modify matrix in-place instead.
46+
*/
47+
function setZeroes(matrix: number[][]): void { //NOSONAR
48+
const cols: number[] = []
49+
const rows: number[] = []
50+
for (let i = 0; i < matrix.length; i++) {
51+
for (let j = 0; j < matrix[i].length; j++) {
52+
if (matrix[i][j] === 0) {
53+
if (!rows.includes(i)) rows.push(i)
54+
if (!cols.includes(j)) cols.push(j)
55+
}
56+
}
57+
}
58+
for (const row of matrix) {
59+
for (const col of cols) {
60+
row[col] = 0
61+
}
62+
}
63+
for (let j = 0; j < rows.length; j++) {
64+
for (let i = 0; i < matrix[j].length; i++) {
65+
matrix[rows[j]][i] = 0
66+
}
67+
}
68+
}
69+
70+
export { setZeroes }
71+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 74\. Search a 2D Matrix
5+
6+
Medium
7+
8+
Write an efficient algorithm that searches for a value in an `m x n` matrix. This matrix has the following properties:
9+
10+
* Integers in each row are sorted from left to right.
11+
* The first integer of each row is greater than the last integer of the previous row.
12+
13+
**Example 1:**
14+
15+
![](https://assets.leetcode.com/uploads/2020/10/05/mat.jpg)
16+
17+
**Input:** matrix = \[\[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
18+
19+
**Output:** true
20+
21+
**Example 2:**
22+
23+
![](https://assets.leetcode.com/uploads/2020/10/05/mat2.jpg)
24+
25+
**Input:** matrix = \[\[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
26+
27+
**Output:** false
28+
29+
**Constraints:**
30+
31+
* `m == matrix.length`
32+
* `n == matrix[i].length`
33+
* `1 <= m, n <= 100`
34+
* <code>-10<sup>4</sup> <= matrix[i][j], target <= 10<sup>4</sup></code>
35+
36+
## Solution
37+
38+
```typescript
39+
function searchMatrix(matrix: number[][], target: number): boolean {
40+
const [m, n] = [matrix.length, matrix[0].length]
41+
let [l, r] = [0, m * n - 1]
42+
while (l <= r) {
43+
const mid = Math.floor((l + r) / 2)
44+
const row = Math.floor(mid / n)
45+
const col = mid % n
46+
const el = matrix[row][col]
47+
if (el === target) return true
48+
if (el < target) {
49+
l = mid + 1
50+
} else {
51+
r = mid - 1
52+
}
53+
}
54+
return false
55+
}
56+
57+
export { searchMatrix }
58+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 75\. Sort Colors
5+
6+
Medium
7+
8+
Given an array `nums` with `n` objects colored red, white, or blue, sort them **[in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
9+
10+
We will use the integers `0`, `1`, and `2` to represent the color red, white, and blue, respectively.
11+
12+
You must solve this problem without using the library's sort function.
13+
14+
**Example 1:**
15+
16+
**Input:** nums = [2,0,2,1,1,0]
17+
18+
**Output:** [0,0,1,1,2,2]
19+
20+
**Example 2:**
21+
22+
**Input:** nums = [2,0,1]
23+
24+
**Output:** [0,1,2]
25+
26+
**Example 3:**
27+
28+
**Input:** nums = [0]
29+
30+
**Output:** [0]
31+
32+
**Example 4:**
33+
34+
**Input:** nums = [1]
35+
36+
**Output:** [1]
37+
38+
**Constraints:**
39+
40+
* `n == nums.length`
41+
* `1 <= n <= 300`
42+
* `nums[i]` is `0`, `1`, or `2`.
43+
44+
**Follow up:** Could you come up with a one-pass algorithm using only constant extra space?
45+
46+
## Solution
47+
48+
```typescript
49+
const sortColors = (nums: number[]) => {
50+
let i = 0
51+
let num2s = 0
52+
while (i < nums.length) {
53+
const num = nums.shift()
54+
if (num === 0) nums.splice(nums.length - i, 0, 0)
55+
else if (num === 1) nums.splice(nums.length - num2s, 0, 1)
56+
else {
57+
num2s++
58+
nums.push(2)
59+
}
60+
i++
61+
}
62+
}
63+
64+
export { sortColors }
65+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 76\. Minimum Window Substring
5+
6+
Hard
7+
8+
Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window substring** of_ `s` _such that every character in_ `t` _(**including duplicates**) is included in the window. If there is no such substring__, return the empty string_ `""`_._
9+
10+
The testcases will be generated such that the answer is **unique**.
11+
12+
A **substring** is a contiguous sequence of characters within the string.
13+
14+
**Example 1:**
15+
16+
**Input:** s = "ADOBECODEBANC", t = "ABC"
17+
18+
**Output:** "BANC"
19+
20+
**Explanation:** The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
21+
22+
**Example 2:**
23+
24+
**Input:** s = "a", t = "a"
25+
26+
**Output:** "a"
27+
28+
**Explanation:** The entire string s is the minimum window.
29+
30+
**Example 3:**
31+
32+
**Input:** s = "a", t = "aa"
33+
34+
**Output:** ""
35+
36+
**Explanation:** Both 'a's from t must be included in the window. Since the largest window of s only has one 'a', return empty string.
37+
38+
**Constraints:**
39+
40+
* `m == s.length`
41+
* `n == t.length`
42+
* <code>1 <= m, n <= 10<sup>5</sup></code>
43+
* `s` and `t` consist of uppercase and lowercase English letters.
44+
45+
**Follow up:** Could you find an algorithm that runs in `O(m + n)` time?
46+
47+
## Solution
48+
49+
```typescript
50+
function minWindow(s: string, t: string): string { //NOSONAR
51+
const map: Map<string, number> = new Map()
52+
for (const char of t) {
53+
if (map.has(char)) {
54+
map.set(char, map.get(char) + 1)
55+
} else {
56+
map.set(char, 1)
57+
}
58+
}
59+
let minStartIdx = -Infinity,
60+
minEndIdx = Infinity
61+
let remainingChars = t.length
62+
let startIdx = 0
63+
for (let endIdx = 0; endIdx < s.length; endIdx++) {
64+
const endChar = s[endIdx]
65+
if (map.has(endChar)) {
66+
map.set(endChar, map.get(endChar) - 1)
67+
if (map.get(endChar) >= 0) {
68+
remainingChars--
69+
}
70+
}
71+
while (remainingChars === 0) {
72+
if (minEndIdx - minStartIdx > endIdx - startIdx) {
73+
minStartIdx = startIdx
74+
minEndIdx = endIdx
75+
}
76+
const startChar = s[startIdx]
77+
if (map.has(startChar)) {
78+
map.set(startChar, map.get(startChar) + 1)
79+
}
80+
if (map.get(startChar) > 0) {
81+
remainingChars++
82+
}
83+
startIdx++
84+
}
85+
}
86+
return minStartIdx === -Infinity ? '' : s.slice(minStartIdx, minEndIdx + 1)
87+
}
88+
89+
export { minWindow }
90+
```

0 commit comments

Comments
 (0)