diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 000000000..0f29a6f61 --- /dev/null +++ b/.github/workflows/pages.yml @@ -0,0 +1,62 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [ master ] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2' + bundler-cache: true + cache-version: 0 + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v4 + + - name: Install dependencies + run: | + bundle config set --local deployment 'false' + bundle install + + - name: Build with Jekyll + run: bundle exec jekyll build --baseurl "${{ steps.pages.outputs.base_path }}" + env: + JEKYLL_ENV: production + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..92af19ac0 --- /dev/null +++ b/Gemfile @@ -0,0 +1,19 @@ +source "https://rubygems.org" + +gem "github-pages", group: :jekyll_plugins +gem "jekyll-remote-theme" +gem "faraday-retry" + +# Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem +# and associated library. +platforms :mingw, :x64_mingw, :mswin, :jruby do + gem "tzinfo", ">= 1", "< 3" + gem "tzinfo-data" +end + +# Performance-booster for watching directories on Windows +gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin] + +# Lock `http_parser.rb` gem to `v0.6.x` on JRuby builds since newer versions of the gem +# do not have a Java counterpart. +gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby] \ No newline at end of file diff --git a/_config.yml b/_config.yml new file mode 100644 index 000000000..6b6c9ed1c --- /dev/null +++ b/_config.yml @@ -0,0 +1,44 @@ +# GitHub Pages configuration for CS_BASICS cheatsheets +title: CS_BASICS Cheatsheets +description: Computer Science fundamentals and coding interview cheatsheets +author: yennanliu + +# Theme and plugins +plugins: + - jekyll-remote-theme + +# Build settings +markdown: kramdown +highlighter: rouge + +# Include and exclude settings +include: + - doc/cheatsheet +exclude: + - .gitignore + - README.md + - Gemfile + - Gemfile.lock + - node_modules + - vendor + - .bundle + - .sass-cache + - _site + - archived + - workspace + - algorithm/target + - "*.class" + - "*.jar" + - leetcode_python + - leetcode_java + - leetcode_scala + - leetcode_SQL + - algorithm + - data_structure + - system_design + - ref_code + - script + +# GitHub Pages settings +baseurl: "/CS_basics" +url: "https://yennj12.js.org" \ No newline at end of file diff --git a/_layouts/cheatsheet-index.html b/_layouts/cheatsheet-index.html new file mode 100644 index 000000000..6f3b9ca3d --- /dev/null +++ b/_layouts/cheatsheet-index.html @@ -0,0 +1,7 @@ +--- +layout: default +--- + +
+ {{ content }} +
\ No newline at end of file diff --git a/_layouts/cheatsheet.html b/_layouts/cheatsheet.html new file mode 100644 index 000000000..1304bec6e --- /dev/null +++ b/_layouts/cheatsheet.html @@ -0,0 +1,52 @@ +--- +layout: default +--- + +
+
+ + +
+

{{ page.title }}

+ {% if page.description %} +

{{ page.description }}

+ {% endif %} + +
+ {% if page.difficulty %} + {{ page.difficulty }} + {% endif %} + {% if page.category %} + {{ page.category }} + {% endif %} + {% if page.patterns %} + {% for pattern in page.patterns %} + {{ pattern }} + {% endfor %} + {% endif %} +
+
+
+ +
+ {{ content }} +
+ + +
\ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html new file mode 100644 index 000000000..442098e73 --- /dev/null +++ b/_layouts/default.html @@ -0,0 +1,58 @@ + + + + + + {% if page.title %}{{ page.title }} | {% endif %}{{ site.title }} + + + + + + + + +
+
+ +
+
+ +
+
+ {% if page.layout == 'cheatsheet-index' %} +
+

{{ page.title }}

+

{{ page.description | default: site.description }}

+
+ {% endif %} + +
+ {{ content }} +
+
+
+ + + + \ No newline at end of file diff --git a/assets/css/style.scss b/assets/css/style.scss new file mode 100644 index 000000000..92290a3f9 --- /dev/null +++ b/assets/css/style.scss @@ -0,0 +1,635 @@ +--- +--- + +/* Google Cloud Platform inspired design */ + +:root { + --primary-blue: #1a73e8; + --primary-blue-hover: #1557b0; + --secondary-blue: #e8f0fe; + --text-primary: #202124; + --text-secondary: #5f6368; + --text-tertiary: #80868b; + --border-light: #dadce0; + --border-medium: #c4c7c5; + --background-primary: #ffffff; + --background-secondary: #f8f9fa; + --background-card: #ffffff; + --shadow-light: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px rgba(60,64,67,.15); + --shadow-medium: 0 1px 2px rgba(60,64,67,.3), 0 2px 6px rgba(60,64,67,.15); + --shadow-heavy: 0 4px 8px rgba(60,64,67,.3), 0 8px 10px rgba(60,64,67,.15); + --font-google-sans: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; + --font-google-mono: 'Google Sans Mono', 'SF Mono', Monaco, Inconsolata, monospace; +} + +* { + box-sizing: border-box; +} + +body { + font-family: var(--font-google-sans); + font-size: 16px; + line-height: 1.6; + color: var(--text-primary); + background-color: var(--background-primary); + margin: 0; + padding: 0; +} + +.container { + max-width: 1200px; + margin: 0 auto; + padding: 0 24px; +} + +/* Header */ +.header { + background: var(--background-primary); + border-bottom: 1px solid var(--border-light); + position: sticky; + top: 0; + z-index: 100; +} + +.header-content { + display: flex; + align-items: center; + justify-content: space-between; + height: 64px; +} + +.logo-link { + text-decoration: none; + color: var(--text-primary); +} + +.logo-text { + font-size: 22px; + font-weight: 500; + color: var(--primary-blue); +} + +.nav { + display: flex; + gap: 32px; +} + +.nav-link { + text-decoration: none; + color: var(--text-secondary); + font-weight: 400; + transition: color 0.2s ease; +} + +.nav-link:hover { + color: var(--primary-blue); +} + +/* Main Content */ +.main { + min-height: calc(100vh - 64px - 80px); + padding: 40px 0; +} + +/* Hero Section */ +.hero { + text-align: center; + padding: 60px 0; + background: linear-gradient(135deg, var(--secondary-blue) 0%, var(--background-primary) 100%); + border-radius: 12px; + margin-bottom: 48px; +} + +.hero-title { + font-size: 48px; + font-weight: 400; + color: var(--text-primary); + margin: 0 0 16px 0; + letter-spacing: -0.5px; +} + +.hero-subtitle { + font-size: 20px; + color: var(--text-secondary); + margin: 0; + font-weight: 300; +} + +/* Content */ +.content { + max-width: 800px; + margin: 0 auto; +} + +.content h1 { + font-size: 36px; + font-weight: 400; + color: var(--text-primary); + margin: 48px 0 24px 0; + letter-spacing: -0.25px; +} + +.content h2 { + font-size: 28px; + font-weight: 400; + color: var(--text-primary); + margin: 40px 0 20px 0; + padding-bottom: 12px; + border-bottom: 2px solid var(--secondary-blue); + display: flex; + align-items: center; + gap: 12px; +} + +.content h3 { + font-size: 22px; + font-weight: 500; + color: var(--text-primary); + margin: 32px 0 16px 0; +} + +.content p { + color: var(--text-secondary); + margin: 16px 0; + line-height: 1.7; +} + +/* Tables */ +table { + width: 100%; + border-collapse: collapse; + margin: 24px 0; + background: var(--background-card); + border-radius: 8px; + overflow: hidden; + box-shadow: var(--shadow-light); +} + +th, td { + padding: 16px 20px; + text-align: left; + border-bottom: 1px solid var(--border-light); +} + +th { + background: var(--secondary-blue); + font-weight: 500; + color: var(--text-primary); + font-size: 14px; + text-transform: uppercase; + letter-spacing: 0.5px; +} + +td { + color: var(--text-secondary); + font-size: 14px; +} + +tr:hover { + background: var(--background-secondary); +} + +tr:last-child td { + border-bottom: none; +} + +/* Links in tables */ +table a { + color: var(--primary-blue); + text-decoration: none; + font-weight: 500; + padding: 6px 12px; + border-radius: 6px; + transition: all 0.2s ease; + display: inline-block; +} + +table a:hover { + background: var(--secondary-blue); + color: var(--primary-blue-hover); +} + +/* Cards */ +.card { + background: var(--background-card); + border-radius: 12px; + padding: 24px; + margin: 24px 0; + box-shadow: var(--shadow-light); + border: 1px solid var(--border-light); + transition: box-shadow 0.2s ease, transform 0.2s ease; +} + +.card:hover { + box-shadow: var(--shadow-medium); + transform: translateY(-2px); +} + +/* Grid Layout */ +.cheatsheet-grid { + display: grid; + gap: 32px; +} + +/* Code Blocks */ +pre { + background: var(--background-secondary); + border-radius: 8px; + padding: 20px; + overflow-x: auto; + font-family: var(--font-google-mono); + font-size: 14px; + line-height: 1.5; + border: 1px solid var(--border-light); + margin: 24px 0; +} + +code { + font-family: var(--font-google-mono); + background: var(--background-secondary); + padding: 2px 6px; + border-radius: 4px; + font-size: 0.9em; + color: var(--text-primary); +} + +pre code { + background: none; + padding: 0; +} + +/* Lists */ +ul, ol { + padding-left: 24px; + margin: 16px 0; +} + +li { + margin: 8px 0; + color: var(--text-secondary); +} + +li strong { + color: var(--text-primary); +} + +/* Blockquotes */ +blockquote { + border-left: 4px solid var(--primary-blue); + margin: 24px 0; + padding: 16px 24px; + background: var(--secondary-blue); + border-radius: 0 8px 8px 0; + color: var(--text-secondary); + font-style: italic; +} + +/* Footer */ +.footer { + background: var(--background-secondary); + border-top: 1px solid var(--border-light); + padding: 24px 0; + margin-top: 80px; +} + +.footer-content { + display: flex; + justify-content: center; + align-items: center; +} + +.footer-text { + color: var(--text-tertiary); + font-size: 14px; + margin: 0; +} + +.footer-text a { + color: var(--primary-blue); + text-decoration: none; +} + +.footer-text a:hover { + text-decoration: underline; +} + +/* Cheatsheet Specific Styles */ +.cheatsheet-page { + max-width: 900px; + margin: 0 auto; + padding: 0 24px; +} + +.cheatsheet-header { + margin-bottom: 40px; + padding-bottom: 24px; + border-bottom: 2px solid var(--border-light); +} + +.breadcrumb { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 24px; + font-size: 14px; +} + +.breadcrumb-link { + color: var(--primary-blue); + text-decoration: none; + font-weight: 400; +} + +.breadcrumb-link:hover { + text-decoration: underline; +} + +.breadcrumb-separator { + color: var(--text-tertiary); + font-weight: 300; +} + +.breadcrumb-current { + color: var(--text-secondary); + font-weight: 500; +} + +.cheatsheet-title-section { + text-align: left; +} + +.cheatsheet-title { + font-size: 42px; + font-weight: 400; + color: var(--text-primary); + margin: 0 0 16px 0; + letter-spacing: -0.5px; + line-height: 1.2; +} + +.cheatsheet-description { + font-size: 18px; + color: var(--text-secondary); + margin: 0 0 24px 0; + line-height: 1.6; + font-weight: 300; +} + +.cheatsheet-meta { + display: flex; + flex-wrap: wrap; + gap: 8px; + margin-bottom: 24px; +} + +.meta-badge { + display: inline-block; + padding: 6px 12px; + border-radius: 16px; + font-size: 12px; + font-weight: 500; + text-transform: uppercase; + letter-spacing: 0.5px; +} + +.meta-badge.difficulty-easy { + background: #e8f5e8; + color: #2e7d32; + border: 1px solid #c8e6c9; +} + +.meta-badge.difficulty-medium { + background: #fff3e0; + color: #f57c00; + border: 1px solid #ffcc02; +} + +.meta-badge.difficulty-hard { + background: #ffebee; + color: #d32f2f; + border: 1px solid #ffcdd2; +} + +.meta-badge.category { + background: var(--secondary-blue); + color: var(--primary-blue); + border: 1px solid var(--primary-blue); +} + +.meta-badge.pattern { + background: var(--background-secondary); + color: var(--text-secondary); + border: 1px solid var(--border-medium); +} + +.cheatsheet-content { + line-height: 1.7; +} + +.cheatsheet-content h1 { + font-size: 32px; + margin: 48px 0 24px 0; + color: var(--text-primary); + font-weight: 400; +} + +.cheatsheet-content h2 { + font-size: 26px; + margin: 36px 0 18px 0; + color: var(--text-primary); + font-weight: 400; + padding-bottom: 8px; + border-bottom: 1px solid var(--border-light); +} + +.cheatsheet-content h3 { + font-size: 20px; + margin: 28px 0 14px 0; + color: var(--text-primary); + font-weight: 500; +} + +.cheatsheet-content h4 { + font-size: 18px; + margin: 24px 0 12px 0; + color: var(--text-primary); + font-weight: 500; +} + +.cheatsheet-content p { + margin: 16px 0; + color: var(--text-secondary); +} + +.cheatsheet-content ul, +.cheatsheet-content ol { + margin: 16px 0; + padding-left: 28px; +} + +.cheatsheet-content li { + margin: 8px 0; + color: var(--text-secondary); +} + +.cheatsheet-content strong { + color: var(--text-primary); + font-weight: 600; +} + +.cheatsheet-content code { + background: var(--background-secondary); + color: var(--text-primary); + padding: 3px 6px; + border-radius: 4px; + font-size: 0.9em; + font-family: var(--font-google-mono); +} + +.cheatsheet-content pre { + background: var(--background-secondary); + border: 1px solid var(--border-light); + border-radius: 8px; + padding: 20px; + margin: 24px 0; + overflow-x: auto; + font-family: var(--font-google-mono); + font-size: 14px; + line-height: 1.5; +} + +.cheatsheet-content pre code { + background: none; + padding: 0; + color: var(--text-primary); +} + +.cheatsheet-footer { + margin-top: 60px; + padding: 32px 0; + border-top: 1px solid var(--border-light); +} + +.footer-nav { + display: flex; + justify-content: space-between; + align-items: center; +} + +.footer-nav-link { + color: var(--primary-blue); + text-decoration: none; + font-weight: 500; + padding: 12px 20px; + border-radius: 6px; + border: 1px solid var(--primary-blue); + transition: all 0.2s ease; +} + +.footer-nav-link:hover { + background: var(--primary-blue); + color: white; +} + +/* Enhanced Table Styles for Cheatsheets */ +.cheatsheet-content table { + width: 100%; + margin: 28px 0; + border-collapse: collapse; + background: var(--background-card); + border-radius: 8px; + overflow: hidden; + box-shadow: var(--shadow-light); + border: 1px solid var(--border-light); +} + +.cheatsheet-content th { + background: var(--secondary-blue); + padding: 16px 18px; + font-weight: 600; + color: var(--text-primary); + font-size: 13px; + text-transform: uppercase; + letter-spacing: 0.5px; + border-bottom: 2px solid var(--primary-blue); +} + +.cheatsheet-content td { + padding: 14px 18px; + color: var(--text-secondary); + font-size: 14px; + border-bottom: 1px solid var(--border-light); + vertical-align: top; +} + +.cheatsheet-content tr:last-child td { + border-bottom: none; +} + +.cheatsheet-content tr:hover { + background: var(--background-secondary); +} + +/* Responsive Design */ +@media (max-width: 768px) { + .container { + padding: 0 16px; + } + + .header-content { + height: 56px; + } + + .hero-title { + font-size: 32px; + } + + .hero-subtitle { + font-size: 18px; + } + + .nav { + gap: 20px; + } + + .nav-link { + font-size: 14px; + } + + table { + font-size: 12px; + } + + th, td { + padding: 12px 16px; + } + + .card { + padding: 20px; + } +} + +@media (max-width: 480px) { + .hero { + padding: 40px 0; + } + + .hero-title { + font-size: 28px; + } + + .nav { + flex-direction: column; + gap: 12px; + } + + .header-content { + flex-direction: column; + height: auto; + padding: 16px 0; + } + + .header { + position: static; + } +} \ No newline at end of file diff --git a/cheatsheets/index.md b/cheatsheets/index.md new file mode 100644 index 000000000..0ff800fb3 --- /dev/null +++ b/cheatsheets/index.md @@ -0,0 +1,87 @@ +--- +layout: cheatsheet-index +title: Computer Science Cheatsheets +description: Comprehensive cheatsheets covering all major CS topics and algorithmic patterns essential for coding interviews +permalink: /cheatsheets/ +--- + +# Computer Science Cheatsheets + +This collection contains comprehensive cheatsheets covering all major computer science topics and algorithmic patterns essential for coding interviews and software development. + +## 📊 Data Structures + +| Topic | Description | Link | +|-------|-------------|------| +| **Arrays** | Array operations, techniques, and patterns | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/array.html) | +| **Binary Trees** | Tree traversal, construction, and manipulation | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/binary_tree.html) | +| **Binary Search Trees** | BST operations and balancing | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/bst.html) | +| **Graphs** | Graph algorithms, traversal, and analysis | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/graph.html) | +| **Hash Maps** | Hashing techniques and collision handling | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/hash_map.html) | +| **Heaps** | Priority queues and heap operations | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/heap.html) | +| **Linked Lists** | List operations and pointer manipulation | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/linkedlist.html) | + +## 🔍 Algorithm Patterns + +| Pattern | Description | Link | +|---------|-------------|------| +| **Two Pointers** | Efficient array and string processing | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/2_pointers.html) | +| **Binary Search** | Efficient searching in sorted data | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/binary_search.html) | +| **Sliding Window** | Subarray and substring problems | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/sliding_window.html) | +| **Backtracking** | Recursive problem solving | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/backtrack.html) | +| **Dynamic Programming** | Optimization and memoization | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/dp.html) | +| **Greedy Algorithms** | Local optimization strategies | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/greedy.html) | + +## 🌐 Graph Algorithms + +| Algorithm | Description | Link | +|-----------|-------------|------| +| **BFS (Breadth-First Search)** | Level-order traversal and shortest paths | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/bfs.html) | +| **DFS (Depth-First Search)** | Deep exploration and connectivity | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/dfs.html) | +| **Dijkstra's Algorithm** | Single-source shortest paths | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/Dijkstra.html) | +| **Topological Sort** | Dependency resolution and ordering | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/topological_sort.html) | + +## ⚡ Advanced Topics + +| Topic | Description | Link | +|-------|-------------|------| +| **Bit Manipulation** | Bitwise operations and tricks | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/bit_manipulation.html) | +| **System Design** | Scalability and architecture patterns | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/design.html) | +| **Intervals** | Interval merging and scheduling | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/intervals.html) | +| **Math & Geometry** | Mathematical algorithms and computations | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/math.html) | + +## ðŸ’Ą Problem-Solving Techniques + +| Technique | Description | Link | +|-----------|-------------|------| +| **Pattern Recognition** | Common problem patterns and templates | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/dp_pattern.html) | +| **Code Templates** | Reusable code patterns and structures | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/00_template.html) | +| **Java Tricks** | Language-specific optimizations | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/java_trick.html) | +| **Python Tricks** | Python-specific techniques | [View]({{ site.url }}{{ site.baseurl }}/doc/cheatsheet/python_trick.html) | + +--- + +## 📋 Quick Reference + +### Time & Space Complexity Guide +- **O(1)** - Constant time operations +- **O(log n)** - Binary search, balanced trees +- **O(n)** - Linear traversal, single pass +- **O(n log n)** - Efficient sorting, divide & conquer +- **O(nÂē)** - Nested loops, brute force +- **O(2âŋ)** - Exponential, recursive backtracking + +### Common Data Structure Operations + +| Structure | Access | Search | Insertion | Deletion | Space | +|-----------|---------|---------|-----------|----------|-------| +| Array | O(1) | O(n) | O(n) | O(n) | O(n) | +| Dynamic Array | O(1) | O(n) | O(1)* | O(n) | O(n) | +| Hash Table | N/A | O(1)* | O(1)* | O(1)* | O(n) | +| Binary Tree | O(log n)* | O(log n)* | O(log n)* | O(log n)* | O(n) | + +*Average case performance + +--- + +*All cheatsheets are continuously updated with the latest patterns and techniques used in top-tier tech companies.* \ No newline at end of file diff --git a/doc/cheatsheet/00_template.md b/doc/cheatsheet/00_template.md index 2b0f76913..b73fb2cf4 100644 --- a/doc/cheatsheet/00_template.md +++ b/doc/cheatsheet/00_template.md @@ -1,3 +1,15 @@ +--- +layout: cheatsheet +title: "Cheatsheet Template" +description: "Template for creating new cheatsheets with consistent structure" +category: "Template" +difficulty: "Easy" +tags: ["template", "structure", "guide"] +patterns: + - Template structure + - Consistent formatting +--- + # cheatsheet template ## 0) Concept diff --git a/doc/cheatsheet/2_pointers.md b/doc/cheatsheet/2_pointers.md index 23f66c60b..be16d4aaa 100644 --- a/doc/cheatsheet/2_pointers.md +++ b/doc/cheatsheet/2_pointers.md @@ -1,3 +1,20 @@ +--- +layout: cheatsheet +title: "Two Pointers" +description: "Two pointers technique for solving array and string problems efficiently" +category: "Algorithm" +difficulty: "Medium" +tags: ["two-pointers", "array", "string", "sliding-window", "binary-search"] +patterns: + - Fast-slow pointers + - Left-right pointers + - Sliding window + - Binary search + - Array manipulation +time_complexity: "O(n)" +space_complexity: "O(1)" +--- + # Two pointers - Ref diff --git a/doc/cheatsheet/2_pointers_linkedlist.md b/doc/cheatsheet/2_pointers_linkedlist.md index 3f589e9cb..d80248010 100644 --- a/doc/cheatsheet/2_pointers_linkedlist.md +++ b/doc/cheatsheet/2_pointers_linkedlist.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Two Pointers - Linked List" +description: "Two pointer techniques specifically for linked list problems" +category: "Technique" +difficulty: "Medium" +tags: ["two-pointers", "linked-list", "fast-slow", "cycle-detection"] +patterns: + - Fast-slow pointers + - Cycle detection + - Finding middle node +--- + # Two pointers - Linkedlist - Ref diff --git a/doc/cheatsheet/Collection.md b/doc/cheatsheet/Collection.md index 1e762f9a2..f91b61896 100644 --- a/doc/cheatsheet/Collection.md +++ b/doc/cheatsheet/Collection.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Collections" +description: "Collection data structures and operations" +category: "Data Structure" +difficulty: "Easy" +tags: ["collections", "data-structures", "operations"] +patterns: + - Collection operations + - Data manipulation + - Container types +--- + # Collection ## 0) Concept diff --git a/doc/cheatsheet/Dijkstra.md b/doc/cheatsheet/Dijkstra.md index 778ea1c28..d4c97e25b 100644 --- a/doc/cheatsheet/Dijkstra.md +++ b/doc/cheatsheet/Dijkstra.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Dijkstra's Algorithm" +description: "Single-source shortest path algorithm for weighted graphs" +category: "Algorithm" +difficulty: "Hard" +tags: ["dijkstra", "shortest-path", "graph", "greedy", "priority-queue"] +patterns: + - Shortest path finding + - Priority queue usage + - Greedy selection +--- + # Dijkstra's Algorithm ## Overview diff --git a/doc/cheatsheet/add_x_sum.md b/doc/cheatsheet/add_x_sum.md index c4ba3ec36..b1e06b4c6 100644 --- a/doc/cheatsheet/add_x_sum.md +++ b/doc/cheatsheet/add_x_sum.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Add X to Sum" +description: "String addition algorithms and digit-by-digit operations" +category: "Algorithm" +difficulty: "Medium" +tags: ["string", "math", "addition", "carry"] +patterns: + - Digit-by-digit addition + - Carry propagation + - String manipulation +--- + # Add `xxx` to Sum - https://leetcode.com/problems/add-strings/solution/ diff --git a/doc/cheatsheet/array.md b/doc/cheatsheet/array.md index 86086600b..81ee57dc2 100644 --- a/doc/cheatsheet/array.md +++ b/doc/cheatsheet/array.md @@ -1,3 +1,21 @@ +--- +layout: cheatsheet +title: "Array" +description: "Array data structure and common operations for solving linear data problems" +category: "Data Structure" +difficulty: "Easy" +tags: ["array", "data-structure", "indexing", "sorting", "searching", "two-pointers"] +patterns: + - Index manipulation + - Sorting algorithms + - Two pointers + - Sliding window + - Prefix sum + - Array rotation +time_complexity: "O(1) access, O(n) search/insert/delete" +space_complexity: "O(1) for operations, O(n) for storage" +--- + # Array > Basic linear data structure diff --git a/doc/cheatsheet/array_overlap_explaination.md b/doc/cheatsheet/array_overlap_explaination.md index be462b279..a81240e20 100644 --- a/doc/cheatsheet/array_overlap_explaination.md +++ b/doc/cheatsheet/array_overlap_explaination.md @@ -1,3 +1,15 @@ +--- +layout: cheatsheet +title: "Array Overlap Logic Explanation" +description: "Understanding overlapping intervals and booking logic" +category: "Technique" +difficulty: "Medium" +tags: ["intervals", "overlap", "booking", "calendar"] +patterns: + - Interval overlap detection + - Booking systems + - Range checking +--- # Explanation of Overlapping Booking Logic in MyCalendar diff --git a/doc/cheatsheet/backtrack.md b/doc/cheatsheet/backtrack.md index a7d029f48..5155bbde6 100644 --- a/doc/cheatsheet/backtrack.md +++ b/doc/cheatsheet/backtrack.md @@ -1,4 +1,22 @@ -# Bracktrack +--- +layout: cheatsheet +title: "Backtracking" +description: "Backtracking algorithm for solving constraint satisfaction and combinatorial problems" +category: "Algorithm" +difficulty: "Hard" +tags: ["backtracking", "recursion", "dfs", "permutations", "combinations", "constraint-satisfaction"] +patterns: + - Subsets generation + - Permutations + - Combinations + - N-Queens problem + - Sudoku solver + - Word search +time_complexity: "O(2^n) to O(n!) depending on problem" +space_complexity: "O(n) for recursion depth" +--- + +# Backtracking > Brute force via `decision tree process` @@ -1092,7 +1110,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 = {% raw %}{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}{% endraw %}; /** * NOTE !!! * diff --git a/doc/cheatsheet/bfs.md b/doc/cheatsheet/bfs.md index 9a8f473bc..45682024c 100644 --- a/doc/cheatsheet/bfs.md +++ b/doc/cheatsheet/bfs.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "BFS (Breadth-First Search)" +description: "Graph traversal algorithm that explores nodes level by level" +category: "Algorithm" +difficulty: "Medium" +tags: ["bfs", "graph", "tree", "traversal", "queue"] +patterns: + - Level-order traversal + - Shortest path in unweighted graphs + - Queue-based exploration +--- + # BFS (Breadth-First Search) ## Overview diff --git a/doc/cheatsheet/binary_indexed_tree.md b/doc/cheatsheet/binary_indexed_tree.md index 023075ab2..6821e5d8f 100644 --- a/doc/cheatsheet/binary_indexed_tree.md +++ b/doc/cheatsheet/binary_indexed_tree.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Binary Indexed Tree (BIT)" +description: "Fenwick Tree for efficient range queries and point updates" +category: "Data Structure" +difficulty: "Hard" +tags: ["binary-indexed-tree", "fenwick-tree", "range-query", "prefix-sum"] +patterns: + - Point updates + - Range queries + - Prefix sum computation +--- + A Binary Indexed Tree (BIT), also known as a Fenwick Tree, is a data structure that efficiently supports both: Point updates (i.e., update an element in the array). diff --git a/doc/cheatsheet/binary_search.md b/doc/cheatsheet/binary_search.md index fe65689be..da6f46bce 100644 --- a/doc/cheatsheet/binary_search.md +++ b/doc/cheatsheet/binary_search.md @@ -1,3 +1,20 @@ +--- +layout: cheatsheet +title: "Binary Search" +description: "Binary search algorithm for efficiently finding elements in sorted arrays and search spaces" +category: "Algorithm" +difficulty: "Medium" +tags: ["binary-search", "divide-conquer", "sorted-array", "search", "two-pointers"] +patterns: + - Basic binary search + - Search in rotated array + - Find boundaries + - Search in 2D matrix + - Optimization problems +time_complexity: "O(log n)" +space_complexity: "O(1) iterative, O(log n) recursive" +--- + # Binary Search ## Overview @@ -985,7 +1002,7 @@ class Solution: // V0 // IDEA: BINARY SEARCH (fixed by gpt) public int[] searchRange(int[] nums, int target) { - int[] res = new int[]{-1, -1}; // Default result + int[] res = new int[]{% raw %}{-1, -1}{% endraw %}; // Default result if (nums == null || nums.length == 0) { return res; @@ -1000,7 +1017,7 @@ public int[] searchRange(int[] nums, int target) { // Find the last occurrence of target int right = findBound(nums, target, false); - return new int[]{left, right}; + return new int[]{% raw %}{left, right}{% endraw %}; } private int findBound(int[] nums, int target, boolean isFirst) { diff --git a/doc/cheatsheet/binary_tree.md b/doc/cheatsheet/binary_tree.md index 2c2bac729..b28039b13 100644 --- a/doc/cheatsheet/binary_tree.md +++ b/doc/cheatsheet/binary_tree.md @@ -1,3 +1,20 @@ +--- +layout: cheatsheet +title: "Binary Tree" +description: "Binary tree data structure and algorithms for hierarchical data problems" +category: "Data Structure" +difficulty: "Medium" +tags: ["binary-tree", "tree", "dfs", "bfs", "recursion", "traversal"] +patterns: + - Tree traversal (DFS/BFS) + - Tree construction + - Path problems + - Tree properties + - Lowest Common Ancestor +time_complexity: "O(n) for traversal, O(log n) balanced operations" +space_complexity: "O(n) storage, O(h) recursion depth" +--- + # Binary Tree ## Overview diff --git a/doc/cheatsheet/bit_manipulation.md b/doc/cheatsheet/bit_manipulation.md index 65930a893..eef8ea33c 100644 --- a/doc/cheatsheet/bit_manipulation.md +++ b/doc/cheatsheet/bit_manipulation.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Bit Manipulation" +description: "Binary operations and bitwise algorithms for efficient computation" +category: "Technique" +difficulty: "Medium" +tags: ["bit-manipulation", "binary", "bitwise", "optimization"] +patterns: + - Bitwise operations + - Binary representation + - Bit masking +--- + # Bit Manipulation ## 0) Concept diff --git a/doc/cheatsheet/bst.md b/doc/cheatsheet/bst.md index 4d2123084..6bbf22319 100644 --- a/doc/cheatsheet/bst.md +++ b/doc/cheatsheet/bst.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "BST (Binary Search Tree)" +description: "Binary tree with ordering property for efficient search operations" +category: "Data Structure" +difficulty: "Medium" +tags: ["bst", "binary-search-tree", "tree", "search", "ordering"] +patterns: + - In-order traversal + - Search/insert/delete operations + - Tree balancing +--- + # BST (Binary Search Tree) ## Overview diff --git a/doc/cheatsheet/code_interview_general_cheatsheet.md b/doc/cheatsheet/code_interview_general_cheatsheet.md index 422397c0c..b83d15ef0 100644 --- a/doc/cheatsheet/code_interview_general_cheatsheet.md +++ b/doc/cheatsheet/code_interview_general_cheatsheet.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "General Coding Interview Guide" +description: "Comprehensive guide for coding interview preparation and strategies" +category: "Interview" +difficulty: "Easy" +tags: ["interview", "strategy", "preparation", "coding"] +patterns: + - Problem-solving approach + - Communication techniques + - Time management +--- + # Coding Interview Cheatsheet In General ## Answering Steps diff --git a/doc/cheatsheet/design.md b/doc/cheatsheet/design.md index 0dc0598fb..003f3b23d 100644 --- a/doc/cheatsheet/design.md +++ b/doc/cheatsheet/design.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "System Design" +description: "System design patterns and architectural concepts" +category: "System Design" +difficulty: "Hard" +tags: ["system-design", "architecture", "scalability", "patterns"] +patterns: + - Design patterns + - Scalability techniques + - System architecture +--- + # Design ## 0) Concept diff --git a/doc/cheatsheet/dfs.md b/doc/cheatsheet/dfs.md index ceacbf34c..b0b74dcb4 100644 --- a/doc/cheatsheet/dfs.md +++ b/doc/cheatsheet/dfs.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "DFS (Depth-First Search)" +description: "Graph traversal algorithm that explores depth before breadth" +category: "Algorithm" +difficulty: "Medium" +tags: ["dfs", "graph", "tree", "traversal", "recursion"] +patterns: + - Depth-first exploration + - Backtracking + - Path finding +--- + # DFS (Depth-First Search) ## Overview @@ -480,7 +493,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 = {% raw %}{{1, 0}, {-1, 0}, {0, 1}, {0, -1}}{% endraw %}; for (int[] dir : directions) { int newX = x + dir[0]; @@ -1994,7 +2007,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[][]{% raw %}{{0, 1}, {1, 0}, {-1, 0}, {0, -1}}{% endraw %}; for (int[] dir : directions) { int newY = y + dir[0]; int newX = x + dir[1]; diff --git a/doc/cheatsheet/diff_toposort_quickunion.md b/doc/cheatsheet/diff_toposort_quickunion.md index 3f1bf566e..7a0ffb241 100644 --- a/doc/cheatsheet/diff_toposort_quickunion.md +++ b/doc/cheatsheet/diff_toposort_quickunion.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Topological Sort vs Quick Union Comparison" +description: "Quick comparison between topological sorting and union-find algorithms" +category: "Algorithm" +difficulty: "Medium" +tags: ["topological-sort", "union-find", "graph", "comparison"] +patterns: + - Algorithm comparison + - Use case analysis + - Graph processing +--- + # Quick Comparison: Topological Sort vs Quick Union | Feature | Topological Sort | Quick Union (Disjoint Set Union) | diff --git a/doc/cheatsheet/difference_array.md b/doc/cheatsheet/difference_array.md index 72b2dedc6..09ed5d6ea 100644 --- a/doc/cheatsheet/difference_array.md +++ b/doc/cheatsheet/difference_array.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Difference Array" +description: "Efficient range update technique using difference arrays" +category: "Technique" +difficulty: "Medium" +tags: ["difference-array", "range-update", "prefix-sum", "optimization"] +patterns: + - Range updates + - Batch processing + - Array reconstruction +--- + # Difference Array ## Overview diff --git a/doc/cheatsheet/dp.md b/doc/cheatsheet/dp.md index db0daa47e..5ec17ddd9 100644 --- a/doc/cheatsheet/dp.md +++ b/doc/cheatsheet/dp.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Dynamic Programming (DP)" +description: "Algorithmic paradigm for solving optimization problems with overlapping subproblems" +category: "Algorithm" +difficulty: "Hard" +tags: ["dp", "dynamic-programming", "memoization", "optimization"] +patterns: + - Optimal substructure + - Overlapping subproblems + - Memoization +--- + # Dynamic Programming (DP) ## Overview diff --git a/doc/cheatsheet/dp_pattern.md b/doc/cheatsheet/dp_pattern.md index 6755d246c..b2a2c8e4d 100644 --- a/doc/cheatsheet/dp_pattern.md +++ b/doc/cheatsheet/dp_pattern.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "DP Patterns" +description: "Common dynamic programming patterns and problem types" +category: "Algorithm" +difficulty: "Hard" +tags: ["dp", "dynamic-programming", "patterns", "optimization"] +patterns: + - Kadane's algorithm + - Knapsack problems + - Substring patterns +--- + # DP Pattern - https://leetcode.com/discuss/study-guide/1308617/Dynamic-Programming-Patterns diff --git a/doc/cheatsheet/graph.md b/doc/cheatsheet/graph.md index 4843de7f2..abc8633b5 100644 --- a/doc/cheatsheet/graph.md +++ b/doc/cheatsheet/graph.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Graph Algorithms" +description: "Algorithms for solving problems on graph data structures" +category: "Algorithm" +difficulty: "Hard" +tags: ["graph", "traversal", "shortest-path", "connectivity"] +patterns: + - Graph traversal + - Shortest path algorithms + - Connectivity analysis +--- + # Graph Algorithms ## Overview diff --git a/doc/cheatsheet/greedy.md b/doc/cheatsheet/greedy.md index 93383ecf0..87a2eae5d 100644 --- a/doc/cheatsheet/greedy.md +++ b/doc/cheatsheet/greedy.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Greedy Algorithms" +description: "Algorithms that make locally optimal choices for global optimization" +category: "Algorithm" +difficulty: "Medium" +tags: ["greedy", "optimization", "local-optimal", "scheduling"] +patterns: + - Local optimization + - Activity selection + - Interval scheduling +--- + # Greedy Algorithms ## Overview diff --git a/doc/cheatsheet/hash_map.md b/doc/cheatsheet/hash_map.md index c88e927ed..2e74478fb 100644 --- a/doc/cheatsheet/hash_map.md +++ b/doc/cheatsheet/hash_map.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Hash Map" +description: "Hash table data structure for efficient key-value storage and retrieval" +category: "Data Structure" +difficulty: "Easy" +tags: ["hash-map", "dictionary", "hash-table", "key-value"] +patterns: + - Key-value mapping + - Constant time lookup + - Collision handling +--- + # Hash Map Cheatsheet ## Overview diff --git a/doc/cheatsheet/heap.md b/doc/cheatsheet/heap.md index 82e86d030..11cdc7c0f 100644 --- a/doc/cheatsheet/heap.md +++ b/doc/cheatsheet/heap.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Heap Data Structure" +description: "Complete binary tree for efficient priority-based operations" +category: "Data Structure" +difficulty: "Medium" +tags: ["heap", "priority-queue", "binary-tree", "sorting"] +patterns: + - Priority queue operations + - Heap sort algorithm + - Top K elements +--- + # Heap Data Structure ## Overview diff --git a/doc/cheatsheet/intervals.md b/doc/cheatsheet/intervals.md index 93f1da0b6..524466a80 100644 --- a/doc/cheatsheet/intervals.md +++ b/doc/cheatsheet/intervals.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Intervals" +description: "Problems involving ranges and interval operations like merging and scheduling" +category: "Technique" +difficulty: "Medium" +tags: ["intervals", "ranges", "merging", "scheduling", "overlap"] +patterns: + - Interval merging + - Overlap detection + - Meeting scheduling +--- + # Intervals ## Overview diff --git a/doc/cheatsheet/iterator.md b/doc/cheatsheet/iterator.md index 11f1f78cf..61e4b712e 100644 --- a/doc/cheatsheet/iterator.md +++ b/doc/cheatsheet/iterator.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Iterator" +description: "Design pattern for traversing elements in collections" +category: "Data Structure" +difficulty: "Easy" +tags: ["iterator", "traversal", "design-pattern", "collections"] +patterns: + - Sequential access + - Collection traversal + - Design pattern implementation +--- + # Iterator ## 0) Concept diff --git a/doc/cheatsheet/java_trick.md b/doc/cheatsheet/java_trick.md index b9921db34..7e3070220 100644 --- a/doc/cheatsheet/java_trick.md +++ b/doc/cheatsheet/java_trick.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Java Programming Tricks" +description: "Essential Java programming tricks and patterns for competitive programming" +category: "Language" +difficulty: "Medium" +tags: ["java", "tricks", "patterns", "competitive-programming"] +patterns: + - Java syntax shortcuts + - Collections best practices + - Performance optimizations +--- + # Java Programming Tricks & Patterns ## Overview @@ -109,7 +122,7 @@ int[] arr3 = new int[]{1, 2, 3, 4, 5}; // Explicit initialization // 2D Array Initialization int[][] matrix = new int[3][4]; // 3 rows, 4 columns (all zeros) -int[][] matrix2 = {{1, 2}, {3, 4}, {5, 6}}; // Direct 2D initialization +int[][] matrix2 = {% raw %}{{1, 2}, {3, 4}, {5, 6}}{% endraw %}; // Direct 2D initialization // Dynamic 2D array (common in LeetCode) int k = 4; @@ -754,9 +767,9 @@ Arrays.sort(words, Collections.reverseOrder()); // Reverse order #### 2D Array Sorting ```java // Sort by first element -int[][] intervals = {{15,20}, {0,30}, {5,10}}; +int[][] intervals = {% raw %}{{15,20}, {0,30}, {5,10}}{% endraw %}; Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0])); -// Result: {{0,30}, {5,10}, {15,20}} +// Result: {% raw %}{{0,30}, {5,10}, {15,20}}{% endraw %} // Multi-criteria sorting (primary: descending, secondary: ascending) Arrays.sort(people, (a, b) -> { @@ -789,30 +802,30 @@ Arrays.sort(people, new Comparator() { #### In-Place Sorting (Recommended) ```java -int[][] intervals = {{15,20}, {0,30}, {5,10}}; +int[][] intervals = {% raw %}{{15,20}, {0,30}, {5,10}}{% endraw %}; // Sorts original array directly Arrays.sort(intervals, (a, b) -> Integer.compare(a[0], b[0])); -// intervals is now: {{0,30}, {5,10}, {15,20}} +// intervals is now: {% raw %}{{0,30}, {5,10}, {15,20}}{% endraw %} ``` #### Stream Sorting (Functional Style) ```java -int[][] intervals = {{15,20}, {0,30}, {5,10}}; +int[][] intervals = {% raw %}{{15,20}, {0,30}, {5,10}}{% endraw %}; // Original array unchanged, returns sorted stream int[][] sorted = Arrays.stream(intervals) .sorted((a, b) -> Integer.compare(a[0], b[0])) .toArray(int[][]::new); // Must collect to get array -// Original intervals still: {{15,20}, {0,30}, {5,10}} -// sorted is: {{0,30}, {5,10}, {15,20}} +// Original intervals still: {% raw %}{{15,20}, {0,30}, {5,10}}{% endraw %} +// sorted is: {% raw %}{{0,30}, {5,10}, {15,20}}{% endraw %} ``` **Demonstration:** ```java -int[][] intervals = {{15,20}, {0,30}, {5,10}}; +int[][] intervals = {% raw %}{{15,20}, {0,30}, {5,10}}{% endraw %}; System.out.println("Original: " + Arrays.deepToString(intervals)); // Stream sorting - original unchanged @@ -1284,7 +1297,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[][]{% raw %}{{0, 1}, {1, 0}, {-1, 0}, {0, -1}}{% endraw %}; ``` ### 1-18) Arrays.fill (1 D) diff --git a/doc/cheatsheet/kadane_algo.md b/doc/cheatsheet/kadane_algo.md index 09a0143dd..7e2ee05b2 100644 --- a/doc/cheatsheet/kadane_algo.md +++ b/doc/cheatsheet/kadane_algo.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Kadane Algorithm" +description: "Dynamic programming algorithm for maximum subarray sum problems" +category: "Algorithm" +difficulty: "Medium" +tags: ["kadane", "dynamic-programming", "subarray", "maximum-sum"] +patterns: + - Maximum subarray sum + - Single-pass optimization + - Dynamic programming +--- + # Kadane Algorithm diff --git a/doc/cheatsheet/linked_list.md b/doc/cheatsheet/linked_list.md index 86dc14f8e..21f84d78b 100644 --- a/doc/cheatsheet/linked_list.md +++ b/doc/cheatsheet/linked_list.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Linked List" +description: "Linear data structure with nodes containing data and pointers" +category: "Data Structure" +difficulty: "Easy" +tags: ["linked-list", "pointers", "reversal", "traversal"] +patterns: + - List reversal + - Two-pointer techniques + - Dummy node usage +--- + # Linked List ## 0) Concept diff --git a/doc/cheatsheet/math.md b/doc/cheatsheet/math.md index a59159e7f..1ab3d91dd 100644 --- a/doc/cheatsheet/math.md +++ b/doc/cheatsheet/math.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Math" +description: "Mathematical concepts and algorithms for problem solving" +category: "Technique" +difficulty: "Medium" +tags: ["math", "algorithms", "number-theory", "geometry"] +patterns: + - Mathematical formulas + - Number theory + - Geometric algorithms +--- + # Math ## 0) Concept diff --git a/doc/cheatsheet/matrix.md b/doc/cheatsheet/matrix.md index b8e27cf78..8481d56a2 100644 --- a/doc/cheatsheet/matrix.md +++ b/doc/cheatsheet/matrix.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Matrix Data Structure" +description: "2-dimensional array for grid-based problems and mathematical computations" +category: "Data Structure" +difficulty: "Medium" +tags: ["matrix", "2d-array", "grid", "traversal"] +patterns: + - Matrix traversal + - Grid-based problems + - 2D dynamic programming +--- + # Matrix Data Structure ## Overview diff --git a/doc/cheatsheet/monotonic_stack.md b/doc/cheatsheet/monotonic_stack.md index 9b4330a73..d2e67acd7 100644 --- a/doc/cheatsheet/monotonic_stack.md +++ b/doc/cheatsheet/monotonic_stack.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Monotonic Stack" +description: "Specialized stack maintaining monotonic order for optimization problems" +category: "Data Structure" +difficulty: "Hard" +tags: ["monotonic-stack", "stack", "optimization", "histogram"] +patterns: + - Next greater/smaller element + - Histogram problems + - Sequence optimization +--- + # Monotonic Stack Data Structure ## Overview diff --git a/doc/cheatsheet/n_sum.md b/doc/cheatsheet/n_sum.md index 07b05ef47..833e94ce4 100644 --- a/doc/cheatsheet/n_sum.md +++ b/doc/cheatsheet/n_sum.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "N Sum" +description: "Techniques for solving N-sum problems with various approaches" +category: "Technique" +difficulty: "Medium" +tags: ["n-sum", "two-pointers", "hash-map", "target-sum"] +patterns: + - Two-pointer approach + - Hash map lookup + - Nested sum problems +--- + # N Sum ## 0) Concept diff --git a/doc/cheatsheet/palindrome.md b/doc/cheatsheet/palindrome.md index 1417bcb41..7ed6c3fe6 100644 --- a/doc/cheatsheet/palindrome.md +++ b/doc/cheatsheet/palindrome.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Palindrome" +description: "Sequence that reads the same forward and backward" +category: "Technique" +difficulty: "Medium" +tags: ["palindrome", "string", "two-pointers", "validation"] +patterns: + - Two-pointer validation + - Substring generation + - Character comparison +--- + # Palindrome (回文) ## Overview diff --git a/doc/cheatsheet/prefix_sum.md b/doc/cheatsheet/prefix_sum.md index 80a5ed83b..02c337403 100644 --- a/doc/cheatsheet/prefix_sum.md +++ b/doc/cheatsheet/prefix_sum.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Prefix Sum" +description: "Preprocessing technique for efficient subarray sum queries" +category: "Technique" +difficulty: "Easy" +tags: ["prefix-sum", "subarray", "range-query", "preprocessing"] +patterns: + - Range sum queries + - Subarray operations + - Cumulative computation +--- + # Prefix Sum (å‰įž€å’Œ)

diff --git a/doc/cheatsheet/priority_queue.md b/doc/cheatsheet/priority_queue.md index e30642a3a..36ee6448c 100644 --- a/doc/cheatsheet/priority_queue.md +++ b/doc/cheatsheet/priority_queue.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Priority Queue" +description: "Abstract data type for priority-based element processing" +category: "Data Structure" +difficulty: "Medium" +tags: ["priority-queue", "heap", "priority-based", "queue"] +patterns: + - Priority-based processing + - Heap implementation + - Task scheduling +--- + # Priority Queue (PQ) Data Structure ## Overview @@ -159,7 +172,7 @@ public int[] mergeKSortedArrays(int[][] arrays) { // Initialize PQ with first element from each array for (int i = 0; i < arrays.length; i++) { if (arrays[i].length > 0) { - pq.offer(new int[]{arrays[i][0], i, 0}); + pq.offer(new int[]{% raw %}{arrays[i][0], i, 0}{% endraw %}); totalSize += arrays[i].length; } } @@ -356,7 +369,7 @@ public int dijkstra(Map> graph, int start, int end) { Map distances = new HashMap<>(); Set visited = new HashSet<>(); - pq.offer(new int[]{0, start}); + pq.offer(new int[]{% raw %}{0, start}{% endraw %}); distances.put(start, 0); while (!pq.isEmpty()) { @@ -379,7 +392,7 @@ public int dijkstra(Map> graph, int start, int end) { if (!distances.containsKey(neighbor) || newDist < distances.get(neighbor)) { distances.put(neighbor, newDist); - pq.offer(new int[]{newDist, neighbor}); + pq.offer(new int[]{% raw %}{newDist, neighbor}{% endraw %}); } } } diff --git a/doc/cheatsheet/python_trick.md b/doc/cheatsheet/python_trick.md index 982554b47..f8178bad0 100644 --- a/doc/cheatsheet/python_trick.md +++ b/doc/cheatsheet/python_trick.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Python Tricks" +description: "Essential Python programming tricks and patterns for efficient coding" +category: "Language" +difficulty: "Medium" +tags: ["python", "tricks", "patterns", "optimization"] +patterns: + - Pythonic code patterns + - Built-in functions + - Data structure operations +--- + # Python Tricks ## 1) Examples diff --git a/doc/cheatsheet/queue.md b/doc/cheatsheet/queue.md index f9e1c58f0..e005fef06 100644 --- a/doc/cheatsheet/queue.md +++ b/doc/cheatsheet/queue.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Queue Data Structure" +description: "Linear data structure following FIFO (First In First Out) principle" +category: "Data Structure" +difficulty: "Easy" +tags: ["queue", "fifo", "linear", "enqueue", "dequeue"] +patterns: + - FIFO processing + - Level-order traversal + - Buffer management +--- + # Queue Data Structure

diff --git a/doc/cheatsheet/quick_find.md b/doc/cheatsheet/quick_find.md index ddf87b44b..ad599e328 100644 --- a/doc/cheatsheet/quick_find.md +++ b/doc/cheatsheet/quick_find.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Quick Find" +description: "Union-find data structure with quick find operations" +category: "Data Structure" +difficulty: "Medium" +tags: ["union-find", "quick-find", "disjoint-set", "connectivity"] +patterns: + - Union-find operations + - Connectivity queries + - Disjoint set management +--- + # Quick Find ## 0) Concept diff --git a/doc/cheatsheet/recursion.md b/doc/cheatsheet/recursion.md index e6dc814c6..22d35b718 100644 --- a/doc/cheatsheet/recursion.md +++ b/doc/cheatsheet/recursion.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Recursion" +description: "Problem-solving technique using self-calling functions" +category: "Algorithm" +difficulty: "Medium" +tags: ["recursion", "divide-and-conquer", "base-case", "recursive-call"] +patterns: + - Base case definition + - Recursive case breakdown + - Function call stack +--- + # Recursion For a problem, if there exists a recursive solution, we can follow the guidelines below to implement it. diff --git a/doc/cheatsheet/recursion_and_dp.md b/doc/cheatsheet/recursion_and_dp.md index 5b2582330..8600fce86 100644 --- a/doc/cheatsheet/recursion_and_dp.md +++ b/doc/cheatsheet/recursion_and_dp.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Recursion and Dynamic Programming" +description: "Relationship between recursion and dynamic programming optimization" +category: "Algorithm" +difficulty: "Hard" +tags: ["recursion", "dp", "dynamic-programming", "optimization"] +patterns: + - Recursive to DP conversion + - Memoization techniques + - Bottom-up optimization +--- + # Dynamic Programming ## 0) Concept diff --git a/doc/cheatsheet/scanning_line.md b/doc/cheatsheet/scanning_line.md index deee6be8a..b1aed2714 100644 --- a/doc/cheatsheet/scanning_line.md +++ b/doc/cheatsheet/scanning_line.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Scanning Line (Line Sweep)" +description: "Algorithmic paradigm for processing geometric objects with sweep line technique" +category: "Algorithm" +difficulty: "Hard" +tags: ["scanning-line", "line-sweep", "geometric", "intervals"] +patterns: + - Event-based processing + - Geometric problem solving + - Interval processing +--- + # Scanning Line (Line Sweep) Algorithm ## Overview @@ -117,8 +130,8 @@ public int maxOverlap(int[][] intervals) { // Create events for (int[] interval : intervals) { - events.add(new int[]{interval[0], 1}); // Start - events.add(new int[]{interval[1], -1}); // End + events.add(new int[]{% raw %}{interval[0], 1}{% endraw %}); // Start + events.add(new int[]{% raw %}{interval[1], -1}{% endraw %}); // End } // Sort events @@ -248,8 +261,8 @@ public List> getSkyline(int[][] buildings) { List events = new ArrayList<>(); for (int[] b : buildings) { - events.add(new int[]{b[0], -b[2]}); // Start - events.add(new int[]{b[1], b[2]}); // End + events.add(new int[]{% raw %}{b[0], -b[2]}{% endraw %}); // Start + events.add(new int[]{% raw %}{b[1], b[2]}{% endraw %}); // End } Collections.sort(events, (a, b) -> { @@ -321,8 +334,8 @@ class MyCalendarTwo { } public boolean book(int start, int end) { - events.add(new int[]{start, 1}); - events.add(new int[]{end, -1}); + events.add(new int[]{% raw %}{start, 1}{% endraw %}); + events.add(new int[]{% raw %}{end, -1}{% endraw %}); Collections.sort(events, (a, b) -> { if (a[0] != b[0]) return a[0] - b[0]; @@ -333,8 +346,8 @@ class MyCalendarTwo { for (int[] event : events) { booked += event[1]; if (booked >= 3) { - events.remove(new int[]{start, 1}); - events.remove(new int[]{end, -1}); + events.remove(new int[]{% raw %}{start, 1}{% endraw %}); + events.remove(new int[]{% raw %}{end, -1}{% endraw %}); return false; } } diff --git a/doc/cheatsheet/set.md b/doc/cheatsheet/set.md index 1c364fd3a..2d3de5f51 100644 --- a/doc/cheatsheet/set.md +++ b/doc/cheatsheet/set.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Set" +description: "Collection of unique elements with set operations" +category: "Data Structure" +difficulty: "Easy" +tags: ["set", "unique", "hash-set", "tree-set"] +patterns: + - Unique element storage + - Set operations (union, intersection) + - Duplicate elimination +--- + # Set ## 0) Concept diff --git a/doc/cheatsheet/sliding_window.md b/doc/cheatsheet/sliding_window.md index df7789fab..753b6f552 100644 --- a/doc/cheatsheet/sliding_window.md +++ b/doc/cheatsheet/sliding_window.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Sliding Window" +description: "Two-pointer technique for maintaining a window over arrays or strings" +category: "Technique" +difficulty: "Medium" +tags: ["sliding-window", "two-pointers", "window", "optimization"] +patterns: + - Variable window size + - Fixed window size + - Optimal subarray/substring +--- + # Sliding Window ## Overview diff --git a/doc/cheatsheet/sort.md b/doc/cheatsheet/sort.md index 3bc3d5296..36538646c 100644 --- a/doc/cheatsheet/sort.md +++ b/doc/cheatsheet/sort.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Sorting Algorithms" +description: "Collection of sorting algorithms and techniques for arranging data" +category: "Algorithm" +difficulty: "Medium" +tags: ["sorting", "algorithms", "comparison", "stability"] +patterns: + - Comparison-based sorting + - Non-comparison sorting + - Stable vs unstable sorting +--- + # Sorting Algorithms & Techniques

diff --git a/doc/cheatsheet/stack.md b/doc/cheatsheet/stack.md index 621f2481a..bc89a5e03 100644 --- a/doc/cheatsheet/stack.md +++ b/doc/cheatsheet/stack.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Stack" +description: "Linear data structure following LIFO (Last In First Out) principle" +category: "Data Structure" +difficulty: "Easy" +tags: ["stack", "lifo", "linear", "push", "pop"] +patterns: + - LIFO processing + - Function call management + - Expression evaluation +--- + # Stack

@@ -263,7 +276,7 @@ class MyQueue_3{ public int[] nextGreaterElement(int[] nums1, int[] nums2) { if (nums1.length == 1 && nums2.length == 1){ - return new int[]{-1}; + return new int[]{% raw %}{-1}{% endraw %}; } /** @@ -503,7 +516,7 @@ class Solution(object): public int[] nextGreaterElement(int[] nums1, int[] nums2) { if (nums1.length == 1 && nums2.length == 1){ - return new int[]{-1}; + return new int[]{% raw %}{-1}{% endraw %}; } /** diff --git a/doc/cheatsheet/strategy.md b/doc/cheatsheet/strategy.md index c462ed3d9..a7f5d92e5 100644 --- a/doc/cheatsheet/strategy.md +++ b/doc/cheatsheet/strategy.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "LeetCode Strategy" +description: "Strategic approach to solving LeetCode problems effectively" +category: "Interview" +difficulty: "Easy" +tags: ["strategy", "leetcode", "problem-solving", "interview"] +patterns: + - Problem classification + - Solution strategies + - Time/space optimization +--- + ## LC Strategy ### Part 1 : (Top Down)(Input data structure) diff --git a/doc/cheatsheet/string.md b/doc/cheatsheet/string.md index e3793df58..c2a667e51 100644 --- a/doc/cheatsheet/string.md +++ b/doc/cheatsheet/string.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "String Algorithms" +description: "Techniques for processing, searching, and manipulating text data" +category: "Algorithm" +difficulty: "Medium" +tags: ["string", "text-processing", "pattern-matching", "manipulation"] +patterns: + - Pattern matching + - String transformation + - Text parsing +--- + # String Algorithms & Manipulation ## Overview diff --git a/doc/cheatsheet/topology_sorting.md b/doc/cheatsheet/topology_sorting.md index f434b976b..bde1d478d 100644 --- a/doc/cheatsheet/topology_sorting.md +++ b/doc/cheatsheet/topology_sorting.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Topological Sorting" +description: "Linear ordering algorithm for directed acyclic graphs (DAGs)" +category: "Algorithm" +difficulty: "Medium" +tags: ["topological-sort", "dag", "dependency", "ordering"] +patterns: + - Dependency resolution + - DAG processing + - Linear ordering +--- + # Topological Sorting - Complete Guide ## Overview @@ -583,14 +596,14 @@ public class CourseSchedule2 { // ref : https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/AlgorithmJava/TopologicalSortV2.java public int[] findOrder(int numCourses, int[][] prerequisites) { if (numCourses == 1) { - return new int[]{0}; + return new int[]{% raw %}{0}{% endraw %}; } // topologic ordering List ordering = topologicalSort(numCourses, prerequisites); //System.out.println(">>> ordering = " + ordering); if (ordering == null){ - return new int[]{}; + return new int[]{% raw %}{}{% endraw %}; } int[] res = new int[numCourses]; for (int x = 0; x < ordering.size(); x++) { diff --git a/doc/cheatsheet/tree.md b/doc/cheatsheet/tree.md index c61b1e8da..7bac5813e 100644 --- a/doc/cheatsheet/tree.md +++ b/doc/cheatsheet/tree.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Tree Data Structure" +description: "Hierarchical data structure with nodes connected by edges" +category: "Data Structure" +difficulty: "Medium" +tags: ["tree", "hierarchical", "nodes", "traversal"] +patterns: + - Tree traversal + - Hierarchical relationships + - Recursive processing +--- + # Tree Data Structure ## Overview diff --git a/doc/cheatsheet/trie.md b/doc/cheatsheet/trie.md index df8c1d501..f73234962 100644 --- a/doc/cheatsheet/trie.md +++ b/doc/cheatsheet/trie.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Trie" +description: "Prefix tree data structure for efficient string operations" +category: "Data Structure" +difficulty: "Hard" +tags: ["trie", "prefix-tree", "string", "search"] +patterns: + - Prefix matching + - String search + - Auto-completion +--- + # Trie > Whenever we come across questions with multiple strings, it is best to think if Trie can help us. - https://leetcode.com/problems/search-suggestions-system/solution/ diff --git a/doc/cheatsheet/union_find.md b/doc/cheatsheet/union_find.md index 0471a5402..8346c60ee 100644 --- a/doc/cheatsheet/union_find.md +++ b/doc/cheatsheet/union_find.md @@ -1,3 +1,16 @@ +--- +layout: cheatsheet +title: "Union Find" +description: "Disjoint set data structure for connectivity and grouping problems" +category: "Data Structure" +difficulty: "Medium" +tags: ["union-find", "disjoint-set", "connectivity", "graph"] +patterns: + - Connectivity queries + - Dynamic connectivity + - Cycle detection +--- + # Union Find > Check "connection status" for nodes in graphs diff --git a/index.md b/index.md new file mode 100644 index 000000000..e88ae1771 --- /dev/null +++ b/index.md @@ -0,0 +1,57 @@ +--- +layout: default +title: CS_BASICS - Computer Science Fundamentals +description: Comprehensive computer science fundamentals and coding interview preparation materials +--- + +
+

CS_BASICS

+

Computer Science Fundamentals & Interview Preparation

+
+ +Welcome to CS_BASICS! This comprehensive resource contains everything you need for computer science fundamentals and coding interview preparation. + +## 📚 Available Resources + +### [Cheatsheets]({{ site.url }}{{ site.baseurl }}/cheatsheets/) +Comprehensive cheatsheets covering all major computer science topics and algorithmic patterns: + +- **Data Structures**: Arrays, Linked Lists, Trees, Graphs, Hash Tables +- **Algorithms**: Sorting, Searching, Dynamic Programming, Greedy Algorithms +- **Problem Patterns**: Two Pointers, Sliding Window, Backtracking, BFS/DFS +- **System Design**: Distributed Systems, Scalability, Database Design + +### Code Solutions +- **Python**: LeetCode solutions in Python +- **Java**: LeetCode solutions in Java +- **SQL**: Database problem solutions +- **Scala**: Functional programming solutions + +## ðŸŽŊ Quick Navigation + +| Category | Description | Link | +|----------|-------------|------| +| **Algorithms** | Core algorithm implementations | [View](/algorithm/) | +| **Data Structures** | Fundamental data structure concepts | [View](/data_structure/) | +| **LeetCode Python** | Python problem solutions | [View](/leetcode_python/) | +| **LeetCode Java** | Java problem solutions | [View](/leetcode_java/) | +| **System Design** | System design concepts and examples | [View](/system_design/) | + +## 🔗 External Resources + +- [LeetCode Profile](https://leetcode.com/) +- [Blind Curated 75](https://leetcode.com/list/xoqag3yj/) +- [Grind 75](https://www.techinterviewhandbook.org/grind75/) +- [NeetCode 150](https://neetcode.io/practice) + +## 📈 Complexity References + +The repository includes visual references for: +- Big O complexity charts +- Common data structure operation costs +- Sorting algorithm complexities +- Algorithm performance comparisons + +--- + +*This site is automatically generated from the [CS_BASICS GitHub repository](https://github.com/yennanliu/CS_basics).* \ No newline at end of file