diff --git a/.github/workflows/deploy-cheatsheet.yml b/.github/workflows/deploy-cheatsheet.yml new file mode 100644 index 000000000..47061d65a --- /dev/null +++ b/.github/workflows/deploy-cheatsheet.yml @@ -0,0 +1,37 @@ +# # .github/workflows/deploy-cheatsheet.yml + +# name: Deploy Cheatsheet to GitHub Pages + +# on: +# push: +# branches: [ main ] # Or your default branch +# paths: +# - 'doc/cheatsheet/**' + +# permissions: +# contents: read +# pages: write +# id-token: write + +# concurrency: +# group: 'pages' +# cancel-in-progress: true + +# jobs: +# deploy: +# runs-on: ubuntu-latest + +# steps: +# - name: Checkout Repository +# uses: actions/checkout@v3 + +# - name: Setup Pages +# uses: actions/configure-pages@v3 + +# - name: Upload Cheatsheet files +# uses: actions/upload-pages-artifact@v2 +# with: +# path: doc/cheatsheet + +# - name: Deploy to GitHub Pages +# uses: actions/deploy-pages@v2 \ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..6863ff872 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,51 @@ +name: Build and Deploy GitHub Pages + +on: + push: + branches: + - main + - master + paths: + - 'doc/cheatsheet/**' # Only trigger when files in doc/cheatsheet change + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler-cache: true + + - name: Create Jekyll site structure + run: | + mkdir -p _layouts _includes _sass assets + # Copy only cheatsheet files to a temporary directory + mkdir -p temp_site/doc/cheatsheet + cp -r doc/cheatsheet/* temp_site/doc/cheatsheet/ + # Create a minimal config file + echo "source: temp_site" > _config.yml + echo "baseurl: /CS_basics" >> _config.yml + echo "title: CS Basics Cheatsheets" >> _config.yml + echo "markdown: kramdown" >> _config.yml + + - name: Install Jekyll and Dependencies + run: | + gem install bundler + bundle init + bundle add jekyll -v "~> 3.9.0" + bundle add github-pages + bundle install + + - name: Build Site + run: bundle exec jekyll build --source temp_site --destination _site + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./_site \ No newline at end of file diff --git a/doc/cheatsheet/backtrack.md b/doc/cheatsheet/backtrack.md index a7d029f48..74d8e95d9 100644 --- a/doc/cheatsheet/backtrack.md +++ b/doc/cheatsheet/backtrack.md @@ -100,7 +100,7 @@ These are often **permutation problems**, where: - You **should revisit** earlier choices (sometimes) --> Don’t use `start_idx` when: +-> Don't use `start_idx` when: - You're generating **permutations** - You need **all orderings** - Choices are not sequential (e.g., trying all positions) @@ -789,10 +789,10 @@ if (i > 0 && nums[i] == nums[i - 1] && !used[i - 1]) // dfsFind(board, word, x+1, y, visited, start_idx + 1) -// 1) You’re passing a copy of start_idx + 1 to the recursive function. So, inside the recursive call, start_idx is a new variable, and changes to it won’t affect the start_idx in the calling function. +// 1) You're passing a copy of start_idx + 1 to the recursive function. So, inside the recursive call, start_idx is a new variable, and changes to it won't affect the start_idx in the calling function. -// 2) We don’t need start_idx -= 1; because start_idx is passed by value, not by reference. So modifying it in the recursive call doesn’t affect the caller’s start_idx. We’re already handling the correct index in each recursive call by passing start_idx + 1. +// 2) We don't need start_idx -= 1; because start_idx is passed by value, not by reference. So modifying it in the recursive call doesn't affect the caller's start_idx. We're already handling the correct index in each recursive call by passing start_idx + 1. ``` @@ -1092,7 +1092,7 @@ private boolean dfs_(char[][] board, int y, int x, int idx, String word, boolean /** NOTE !!! we update visited on x, y here */ visited[y][x] = true; - int[][] dirs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; + int[][] dirs = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} }; /** * NOTE !!! * @@ -1198,13 +1198,13 @@ class Solution(object): // V0' // IDEA : Backtracking // https://leetcode.com/problems/subsets/editorial/ - List> output = new ArrayList(); + List> output = new ArrayList<>(); int n, k; public void backtrack(int first, ArrayList curr, int[] nums) { // if the combination is done if (curr.size() == k) { - output.add(new ArrayList(curr)); + output.add(new ArrayList<>(curr)); return; } /** NOTE HERE !!! @@ -1701,9 +1701,9 @@ private void backtrack(String s, int start, List currentList) { * * • This is the base case of the recursion. * - * • It means: “If we’ve reached the end of the string, + * • It means: "If we've reached the end of the string, * then the current list of substrings (currentList) - * forms a valid full partition of s into palindromes.” + * forms a valid full partition of s into palindromes." * * • -> So we add a copy of currentList into * the final result list partitionRes. @@ -1712,9 +1712,9 @@ private void backtrack(String s, int start, List currentList) { * - Why start == s.length()? * * • Because start is the index from which - * we’re currently trying to partition. + * we're currently trying to partition. * - * • If start == s.length(), it means we’ve + * • If start == s.length(), it means we've * used up all characters in s, and currentList is now a full, * valid partition. */ @@ -2039,5 +2039,4 @@ private boolean dfs(int crs, Map> preMap, Set vi visiting.remove(crs); preMap.get(crs).clear(); // Clear prerequisites as the course is confirmed to be processed return true; -} -``` \ No newline at end of file +} \ No newline at end of file diff --git a/doc/cheatsheet/bfs.md b/doc/cheatsheet/bfs.md index 83a2c174e..24e22dd0c 100644 --- a/doc/cheatsheet/bfs.md +++ b/doc/cheatsheet/bfs.md @@ -437,8 +437,8 @@ class Solution: for x, y in q: # get the distance from a gate distance = rooms[x][y]+1 - directions = [(-1,0), (1,0), (0,-1), (0,1)] - for dx, dy in directions: + dirs = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} } + for dx, dy in dirs: # find the INF around the gate new_x, new_y = x+dx, y+dy if 0 <= new_x < row and 0 <= new_y < col and rooms[new_x][new_y] == 2147483647: @@ -484,7 +484,7 @@ class Solution: int space_cnt = 0; int gete_cnt = 0; - int[][] dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; + int[][] dirs = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; int len = rooms.length; int width = rooms[0].length; @@ -1033,7 +1033,7 @@ public int[][] updateMatrix_0_1(int[][] mat) { * * * You perform a **BFS for every 1** in the matrix. * * In worst case, you scan the whole matrix **once per 1**. - * * That’s **O(N × M × (N + M))** — very slow for large inputs. + * * That's **O(N × M × (N + M))** — very slow for large inputs. * * --- * @@ -1043,7 +1043,7 @@ public int[][] updateMatrix_0_1(int[][] mat) { * * #### Why this works: * - * * You flip the problem: instead of asking *“how far is this 1 from a 0?”*, you ask *“how far can each 0 reach a 1?”* + * * You flip the problem: instead of asking *"how far is this 1 from a 0?"*, you ask *"how far can each 0 reach a 1?"* * * When you expand from all 0s **at the same time**, you ensure that **each 1 gets the shortest path to a 0**, because BFS guarantees minimum-distance traversal. * * Time complexity is **O(N × M)** — each cell is visited only once. * @@ -1057,7 +1057,7 @@ public int[][] updateMatrix_0_1(int[][] mat) { } } - int[][] dirs = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; + int[][] dirs = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; // 2️⃣ BFS from all 0s while (!queue.isEmpty()) { diff --git a/doc/cheatsheet/dfs.md b/doc/cheatsheet/dfs.md index 5415a5eb3..8dc305a55 100644 --- a/doc/cheatsheet/dfs.md +++ b/doc/cheatsheet/dfs.md @@ -284,7 +284,7 @@ _is_island(grid, x, y-1, seen); // V2 // private boolean _is_island_2(char[][] grid, int x, int y, boolean[][] seen) {} -int[][] directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; +int[][] directions = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} }; for (int[] dir : directions) { int newX = x + dir[0]; @@ -1681,7 +1681,7 @@ private void dfs(int[][] heights, boolean[][] reachable, int y, int x) { reachable[y][x] = true; - int[][] directions = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; + int[][] directions = new int[][]{ {0, 1}, {1, 0}, {-1, 0}, {0, -1} }; for (int[] dir : directions) { int newY = y + dir[0]; int newX = x + dir[1]; @@ -1771,7 +1771,7 @@ private void reveal_1(char[][] board, int x, int y) { * and avoid unnecessary recursion. * * - 3) board[x][y] != 'E' - * • Avoids re-processing non-‘E’ cells + * • Avoids re-processing non-'E' cells * • The board can have: * • 'M' → Mine (already handled separately) * • 'X' → Clicked mine (game over case) @@ -1795,7 +1795,7 @@ private void reveal_1(char[][] board, int x, int y) { * • Counts 1 mine nearby → Updates board[0][0] = '1' * • Does NOT recurse further, avoiding unnecessary work. * - * What If We Didn’t Check board[x][y] != 'E'? + * What If We Didn't Check board[x][y] != 'E'? * • It might try to expand into already processed cells, leading to redundant computations or infinite recursion. * */ diff --git a/doc/cheatsheet/java_trick.md b/doc/cheatsheet/java_trick.md index 44cd9d833..1071ce221 100644 --- a/doc/cheatsheet/java_trick.md +++ b/doc/cheatsheet/java_trick.md @@ -325,7 +325,7 @@ public List> levelOrder(TreeNode root) { * * • res is a List>, where each inner list represents a level of the tree. * • res.get(depth) retrieves the list at the given depth. -* • .add(curRoot.val) adds the current node’s value to the corresponding depth level. +* • .add(curRoot.val) adds the current node's value to the corresponding depth level. * */ @@ -1254,7 +1254,7 @@ return true; ```java // java // LC 417 -public int[][] DIRECTIONS = new int[][]{{0, 1}, {1, 0}, {-1, 0}, {0, -1}}; +public int[][] DIRECTIONS = new int[][]{ {0, 1}, {1, 0}, {-1, 0}, {0, -1} }; ``` ### 1-18) Arrays.fill (1 D) @@ -1640,7 +1640,7 @@ orderMap[order.charAt(i) - 'a'] = i; ### 🔍 What's happening? -Let’s say: +Let's say: ```java order = "hlabcdefgijkmnopqrstuvwxyz"; ``` diff --git a/doc/cheatsheet/matrix.md b/doc/cheatsheet/matrix.md index 736307cee..11985a0a5 100644 --- a/doc/cheatsheet/matrix.md +++ b/doc/cheatsheet/matrix.md @@ -466,7 +466,7 @@ class Solution(object): * -> so we have 3 layer loop as below: * - i : Iterates over the rows of A (outer loop). * - j : Iterates over the columns of B (second loop). -* - k : Iterates over the “shared dimension” (columns of A or rows of B ) to compute the dot product (inner loop). +* - k : Iterates over the "shared dimension" (columns of A or rows of B ) to compute the dot product (inner loop). * * * -> @@ -474,7 +474,7 @@ class Solution(object): * The Role of the Loops * 1. Outer loop ( i ): Iterates over the rows of mat1 to calculate each row of the result matrix. * 2. Middle loop ( j ): Iterates over the columns of mat2 to compute each element in a row of the result matrix. -* 3. Inner loop ( k ): Iterates over the “shared dimension” to compute the dot product of the i^{th} row of mat1 and the j^{th} column of mat2. +* 3. Inner loop ( k ): Iterates over the "shared dimension" to compute the dot product of the i^{th} row of mat1 and the j^{th} column of mat2. * * * -> Why the Inner Loop ( k ) Exists ? @@ -488,7 +488,7 @@ class Solution(object): public static int[][] multiply(int[][] mat1, int[][] mat2) { // Edge case: Single element matrices if (mat1.length == 1 && mat1[0].length == 1 && mat2.length == 1 && mat2[0].length == 1) { - return new int[][]{{mat1[0][0] * mat2[0][0]}}; + return new int[][]{ {mat1[0][0] * mat2[0][0]} }; } int l_1 = mat1.length; // Number of rows in mat1 diff --git a/ref_code/CtCI-6th-Edition-master/.project b/ref_code/CtCI-6th-Edition-master/.project index 5ac318607..fe136ff4b 100644 --- a/ref_code/CtCI-6th-Edition-master/.project +++ b/ref_code/CtCI-6th-Edition-master/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1751452257593 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/ref_code/crack_code/Cracking-the-Coding-Interview_solutions-master/.project b/ref_code/crack_code/Cracking-the-Coding-Interview_solutions-master/.project index af27846aa..62f96058d 100644 --- a/ref_code/crack_code/Cracking-the-Coding-Interview_solutions-master/.project +++ b/ref_code/crack_code/Cracking-the-Coding-Interview_solutions-master/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1751452257582 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + diff --git a/ref_code/crack_code/CtCI-6th-Edition-master/.project b/ref_code/crack_code/CtCI-6th-Edition-master/.project index 5ac318607..1ae6704e8 100644 --- a/ref_code/crack_code/CtCI-6th-Edition-master/.project +++ b/ref_code/crack_code/CtCI-6th-Edition-master/.project @@ -14,4 +14,15 @@ org.eclipse.jdt.core.javanature + + + 1751452257597 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + +