Skip to content

Commit

Permalink
248th Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Chen committed Nov 2, 2024
1 parent a74adea commit ff750c6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,14 @@ Ace Coding Interview with 75 Qs
[198]: ./src/page-2/198.%20House%20Robber/rob.ts
[790]: ./src/page-8/790.%20Domino%20and%20Tromino%20Tiling/numTilings.ts

| DP - Multidimensional | | |
| --------------------------------------------------------- | -------- | ------ |
| 62. Unique Paths | Solution | Medium |
| 1143. Longest Common Subsequence | Solution | Medium |
| 714. Best Time to Buy and Sell Stock with Transaction Fee | Solution | Medium |
| 72. Edit Distance | Solution | Medium |
| DP - Multidimensional | | |
| --------------------------------------------------------- | -------------- | ------ |
| 62. Unique Paths | [Solution][62] | Medium |
| 1143. Longest Common Subsequence | Solution | Medium |
| 714. Best Time to Buy and Sell Stock with Transaction Fee | Solution | Medium |
| 72. Edit Distance | Solution | Medium |

[62]: ./src/page-1/62.%20Unique%20Paths/uniquePaths.ts

| Bit Manipulation | | |
| --------------------------------------------- | ---------------- | ------ |
Expand Down Expand Up @@ -647,7 +649,7 @@ Must-do List for Interview Prep
| ----------------------------------- | --------------- | ------ |
| 5. Longest Palindromic Substring | [Solution][5] | Medium |
| 32. Longest Valid Parentheses | Solution | Hard |
| 62. Unique Paths | Solution | Medium |
| 62. Unique Paths | [Solution][62] | Medium |
| 64. Minimum Path Sum | Solution | Medium |
| 70. Climbing Stairs | [Solution][70] | Easy |
| 72. Edit Distance | Solution | Medium |
Expand All @@ -662,6 +664,7 @@ Must-do List for Interview Prep
| 1143. Longest Common Subsequence | Solution | Medium |

[5]: ./src/page-1/5.%20Longest%20Palindromic%20Substring/longestPalindrome.ts
[62]: ./src/page-1/62.%20Unique%20Paths/uniquePaths.ts
[70]: ./src/page-1/70.%20Climbing%20Stairs/climbStairs.ts
[118]: ./src/page-2/118.%20Pascal's%20Triangle/generate.ts
[198]: ./src/page-2/198.%20House%20Robber/rob.ts
Expand Down
8 changes: 8 additions & 0 deletions src/page-1/62. Unique Paths/uniquePaths.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { uniquePaths } from './uniquePaths';

describe('62. Unique Paths', () => {
test('uniquePaths', () => {
expect(uniquePaths(3, 7)).toBe(28);
expect(uniquePaths(3, 2)).toBe(3);
});
});
22 changes: 22 additions & 0 deletions src/page-1/62. Unique Paths/uniquePaths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type UniquePaths = (m: number, n: number) => number;

/**
* Accepted
*/
export const uniquePaths: UniquePaths = (m, n) => {
const dp: number[][] = Array.from({ length: m }, () => Array(n).fill(0));

// Initialize the first row and first column
for (let i = 0; i < m; i++) dp[i][0] = 1;
for (let j = 0; j < n; j++) dp[0][j] = 1;

// Fill in the rest of the dp array
for (let i = 1; i < m; i++) {
for (let j = 1; j < n; j++) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}

// The bottom-right corner will contain the number of unique paths
return dp[m - 1][n - 1];
};

0 comments on commit ff750c6

Please sign in to comment.