Skip to content

Commit 1be6773

Browse files
authored
Added tasks 56-72
1 parent 551cf39 commit 1be6773

File tree

16 files changed

+478
-0
lines changed

16 files changed

+478
-0
lines changed

Diff for: README.md

+20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
9090

9191
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9292
|-|-|-|-|-|-
93+
| 0070 |[Climbing Stairs](src/main/js/g0001_0100/s0070_climbing_stairs/solution.js)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
9394

9495
#### Day 13 Bit Manipulation
9596

@@ -176,6 +177,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
176177
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
177178
|-|-|-|-|-|-
178179
| 0045 |[Jump Game II](src/main/js/g0001_0100/s0045_jump_game_ii/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
180+
| 0062 |[Unique Paths](src/main/js/g0001_0100/s0062_unique_paths/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
179181

180182
#### Day 14 Dynamic Programming
181183

@@ -202,6 +204,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
202204

203205
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
204206
|-|-|-|-|-|-
207+
| 0072 |[Edit Distance](src/main/js/g0001_0100/s0072_edit_distance/solution.js)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 5 | 99.01
205208

206209
#### Day 19 Bit Manipulation
207210

@@ -396,6 +399,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
396399

397400
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
398401
|-|-|-|-|-|-
402+
| 0070 |[Climbing Stairs](src/main/js/g0001_0100/s0070_climbing_stairs/solution.js)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
399403

400404
#### Day 3
401405

@@ -465,11 +469,13 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
465469

466470
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
467471
|-|-|-|-|-|-
472+
| 0062 |[Unique Paths](src/main/js/g0001_0100/s0062_unique_paths/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
468473

469474
#### Day 16
470475

471476
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
472477
|-|-|-|-|-|-
478+
| 0064 |[Minimum Path Sum](src/main/js/g0001_0100/s0064_minimum_path_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 83.07
473479

474480
#### Day 17
475481

@@ -486,6 +492,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
486492

487493
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
488494
|-|-|-|-|-|-
495+
| 0072 |[Edit Distance](src/main/js/g0001_0100/s0072_edit_distance/solution.js)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 5 | 99.01
489496

490497
#### Day 20
491498

@@ -840,11 +847,13 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
840847

841848
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
842849
|-|-|-|-|-|-
850+
| 0070 |[Climbing Stairs](src/main/js/g0001_0100/s0070_climbing_stairs/solution.js)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
843851

844852
#### Day 11 Dynamic Programming
845853

846854
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
847855
|-|-|-|-|-|-
856+
| 0062 |[Unique Paths](src/main/js/g0001_0100/s0062_unique_paths/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
848857

849858
#### Day 12 Sliding Window/Two Pointer
850859

@@ -956,6 +965,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
956965

957966
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
958967
|-|-|-|-|-|-
968+
| 0056 |[Merge Intervals](src/main/js/g0001_0100/s0056_merge_intervals/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 81.68
959969

960970
#### Day 18 Stack
961971

@@ -1029,6 +1039,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
10291039
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10301040
|-|-|-|-|-|-
10311041
| 0048 |[Rotate Image](src/main/js/g0001_0100/s0048_rotate_image/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
1042+
| 0056 |[Merge Intervals](src/main/js/g0001_0100/s0056_merge_intervals/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 81.68
10321043

10331044
#### Udemy Linked List
10341045

@@ -1057,6 +1068,9 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
10571068

10581069
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10591070
|-|-|-|-|-|-
1071+
| 0070 |[Climbing Stairs](src/main/js/g0001_0100/s0070_climbing_stairs/solution.js)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1072+
| 0064 |[Minimum Path Sum](src/main/js/g0001_0100/s0064_minimum_path_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 83.07
1073+
| 0072 |[Edit Distance](src/main/js/g0001_0100/s0072_edit_distance/solution.js)| Medium | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 5 | 99.01
10601074
| 0010 |[Regular Expression Matching](src/main/js/g0001_0100/s0010_regular_expression_matching/solution.js)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 4 | 95.52
10611075

10621076
#### Udemy Backtracking/Recursion
@@ -1166,6 +1180,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
11661180

11671181
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11681182
|-|-|-|-|-|-
1183+
| 0056 |[Merge Intervals](src/main/js/g0001_0100/s0056_merge_intervals/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 81.68
11691184

11701185
#### Day 3 Array
11711186

@@ -1272,6 +1287,11 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
12721287

12731288
| # | Title | Difficulty | Tag | Time, ms | Time, %
12741289
|------|----------------|-------------|-------------|----------|---------
1290+
| 0072 |[Edit Distance](src/main/js/g0001_0100/s0072_edit_distance/solution.js)| Medium | 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) | 5 | 99.01
1291+
| 0070 |[Climbing Stairs](src/main/js/g0001_0100/s0070_climbing_stairs/solution.js)| 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) | 0 | 100.00
1292+
| 0064 |[Minimum Path Sum](src/main/js/g0001_0100/s0064_minimum_path_sum/solution.js)| 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) | 3 | 83.07
1293+
| 0062 |[Unique Paths](src/main/js/g0001_0100/s0062_unique_paths/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_15, Level_1_Day_11_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
1294+
| 0056 |[Merge Intervals](src/main/js/g0001_0100/s0056_merge_intervals/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Data_Structure_II_Day_2_Array, Level_2_Day_17_Interval, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 81.68
12751295
| 0055 |[Jump Game](src/main/js/g0001_0100/s0055_jump_game/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_4, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
12761296
| 0053 |[Maximum Subarray](src/main/js/g0001_0100/s0053_maximum_subarray/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Data_Structure_I_Day_1_Array, Dynamic_Programming_I_Day_5, Udemy_Famous_Algorithm, Big_O_Time_O(n)_Space_O(1) | 1 | 85.69
12771297
| 0051 |[N-Queens](src/main/js/g0001_0100/s0051_n_queens/solution.js)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 6 | 96.66
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
56\. Merge Intervals
2+
3+
Medium
4+
5+
Given an array of `intervals` where <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code>, merge all overlapping intervals, and return _an array of the non-overlapping intervals that cover all the intervals in the input_.
6+
7+
**Example 1:**
8+
9+
**Input:** intervals = [[1,3],[2,6],[8,10],[15,18]]
10+
11+
**Output:** [[1,6],[8,10],[15,18]]
12+
13+
**Explanation:** Since intervals [1,3] and [2,6] overlap, merge them into [1,6].
14+
15+
**Example 2:**
16+
17+
**Input:** intervals = [[1,4],[4,5]]
18+
19+
**Output:** [[1,5]]
20+
21+
**Explanation:** Intervals [1,4] and [4,5] are considered overlapping.
22+
23+
**Constraints:**
24+
25+
* <code>1 <= intervals.length <= 10<sup>4</sup></code>
26+
* `intervals[i].length == 2`
27+
* <code>0 <= start<sub>i</sub> <= end<sub>i</sub> <= 10<sup>4</sup></code>
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting
2+
// #Data_Structure_II_Day_2_Array #Level_2_Day_17_Interval #Udemy_2D_Arrays/Matrix
3+
// #Big_O_Time_O(n_log_n)_Space_O(n) #2024_12_10_Time_7_ms_(81.68%)_Space_59.2_MB_(41.78%)
4+
5+
/**
6+
* @param {number[][]} intervals
7+
* @return {number[][]}
8+
*/
9+
var merge = function(intervals) {
10+
// Sort intervals based on the starting points
11+
intervals.sort((a, b) => a[0] - b[0])
12+
13+
const result = []
14+
let current = intervals[0]
15+
result.push(current)
16+
17+
for (const next of intervals) {
18+
if (current[1] >= next[0]) {
19+
// Merge intervals
20+
current[1] = Math.max(current[1], next[1])
21+
} else {
22+
// Move to the next interval
23+
current = next;
24+
result.push(current)
25+
}
26+
}
27+
28+
return result;
29+
};
30+
31+
export { merge }

Diff for: src/main/js/g0001_0100/s0062_unique_paths/readme.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
62\. Unique Paths
2+
3+
Medium
4+
5+
There is a robot on an `m x n` grid. The robot is initially located at the **top-left corner** (i.e., `grid[0][0]`). The robot tries to move to the **bottom-right corner** (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time.
6+
7+
Given the two integers `m` and `n`, return _the number of possible unique paths that the robot can take to reach the bottom-right corner_.
8+
9+
The test cases are generated so that the answer will be less than or equal to <code>2 * 10<sup>9</sup></code>.
10+
11+
**Example 1:**
12+
13+
![](https://assets.leetcode.com/uploads/2018/10/22/robot_maze.png)
14+
15+
**Input:** m = 3, n = 7
16+
17+
**Output:** 28
18+
19+
**Example 2:**
20+
21+
**Input:** m = 3, n = 2
22+
23+
**Output:** 3
24+
25+
**Explanation:** From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
26+
27+
1. Right -> Down -> Down
28+
29+
2. Down -> Down -> Right
30+
31+
3. Down -> Right -> Down
32+
33+
**Constraints:**
34+
35+
* `1 <= m, n <= 100`
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math
2+
// #Combinatorics #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_15
3+
// #Level_1_Day_11_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
4+
// #2024_12_10_Time_0_ms_(100.00%)_Space_49.1_MB_(57.14%)
5+
6+
/**
7+
* @param {number} m
8+
* @param {number} n
9+
* @return {number}
10+
*/
11+
var uniquePaths = function(m, n) {
12+
// Initialize a 2D array with all values set to 0
13+
const dp = Array.from({ length: m }, () => Array(n).fill(0))
14+
15+
// Fill the first row and first column with 1
16+
for (let i = 0; i < m; i++) {
17+
dp[i][0] = 1
18+
}
19+
for (let j = 0; j < n; j++) {
20+
dp[0][j] = 1
21+
}
22+
23+
// Fill the rest of the dp table
24+
for (let i = 1; i < m; i++) {
25+
for (let j = 1; j < n; j++) {
26+
dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
27+
}
28+
}
29+
30+
// The answer is in the bottom-right corner
31+
return dp[m - 1][n - 1]
32+
};
33+
34+
export { uniquePaths }
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
64\. Minimum Path Sum
2+
3+
Medium
4+
5+
Given a `m x n` `grid` filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
6+
7+
**Note:** You can only move either down or right at any point in time.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/11/05/minpath.jpg)
12+
13+
**Input:** grid = [[1,3,1],[1,5,1],[4,2,1]]
14+
15+
**Output:** 7
16+
17+
**Explanation:** Because the path 1 → 3 → 1 → 1 → 1 minimizes the sum.
18+
19+
**Example 2:**
20+
21+
**Input:** grid = [[1,2,3],[4,5,6]]
22+
23+
**Output:** 12
24+
25+
**Constraints:**
26+
27+
* `m == grid.length`
28+
* `n == grid[i].length`
29+
* `1 <= m, n <= 200`
30+
* `0 <= grid[i][j] <= 100`
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Matrix
2+
// #Dynamic_Programming_I_Day_16 #Udemy_Dynamic_Programming #Big_O_Time_O(m*n)_Space_O(m*n)
3+
// #2024_12_10_Time_3_ms_(83.07%)_Space_51.2_MB_(74.79%)
4+
5+
/**
6+
* @param {number[][]} grid
7+
* @return {number}
8+
*/
9+
var minPathSum = function(grid) {
10+
const rows = grid.length
11+
const cols = grid[0].length
12+
13+
// Handle the special case where grid has only one cell
14+
if (rows === 1 && cols === 1) {
15+
return grid[0][0]
16+
}
17+
18+
// Create a 2D array for dynamic programming
19+
const dm = Array.from({ length: rows }, () => Array(cols).fill(0))
20+
21+
// Initialize the last column
22+
let s = 0
23+
for (let r = rows - 1; r >= 0; r--) {
24+
dm[r][cols - 1] = grid[r][cols - 1] + s
25+
s += grid[r][cols - 1]
26+
}
27+
28+
// Initialize the last row
29+
s = 0
30+
for (let c = cols - 1; c >= 0; c--) {
31+
dm[rows - 1][c] = grid[rows - 1][c] + s
32+
s += grid[rows - 1][c]
33+
}
34+
35+
// Recursive helper function
36+
const recur = (r, c) => {
37+
if (
38+
dm[r][c] === 0 &&
39+
r !== rows - 1 &&
40+
c !== cols - 1
41+
) {
42+
dm[r][c] =
43+
grid[r][c] +
44+
Math.min(
45+
recur(r + 1, c),
46+
recur(r, c + 1)
47+
)
48+
}
49+
return dm[r][c]
50+
}
51+
52+
// Start recursion from the top-left corner
53+
return recur(0, 0)
54+
};
55+
56+
export { minPathSum }
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
70\. Climbing Stairs
2+
3+
Easy
4+
5+
You are climbing a staircase. It takes `n` steps to reach the top.
6+
7+
Each time you can either climb `1` or `2` steps. In how many distinct ways can you climb to the top?
8+
9+
**Example 1:**
10+
11+
**Input:** n = 2
12+
13+
**Output:** 2
14+
15+
**Explanation:** There are two ways to climb to the top.
16+
17+
1. 1 step + 1 step
18+
19+
2. 2 steps
20+
21+
**Example 2:**
22+
23+
**Input:** n = 3
24+
25+
**Output:** 3
26+
27+
**Explanation:** There are three ways to climb to the top.
28+
29+
1. 1 step + 1 step + 1 step
30+
31+
2. 1 step + 2 steps
32+
33+
3. 2 steps + 1 step
34+
35+
**Constraints:**
36+
37+
* `1 <= n <= 45`

0 commit comments

Comments
 (0)