Skip to content

Latest commit

 

History

History
213 lines (155 loc) · 10.3 KB

File metadata and controls

213 lines (155 loc) · 10.3 KB

Unit-Tested LeetCode Solutions

🔬 Code Health & Testing

C++ Tests Python Tests

🔍 Code Quality & Linting

C++ Linter Python Linter

📊 Repository Stats

Last Commit C++ Solutions Python Solutions

Description

This repository contains comprehensive, unit-tested solutions to LeetCode problems implemented in both C++20 and Python 3. Each solution includes:

  • 🧪 Comprehensive test suites with multiple test cases
  • 📝 Detailed documentation with complexity analysis
  • 🔧 Automated code quality checks and formatting
  • 🚀 CI/CD pipeline with automated testing and linting

📁 Project Structure

├── problems/                    # Problem solutions organized by name
│   ├── two_sum/                 # Individual problem directories
│   │   ├── config.yml           # Problem metadata and configuration
│   │   ├── two_sum.py           # Python solution
│   │   ├── two_sum.cc           # C++ solution
│   │   ├── two_sum.h            # C++ header
│   │   ├── two_sum_test.py      # Python unit tests
│   │   └── two_sum_test.cc      # C++ unit tests
│   └── ...
├── config/                      # Global configuration files
│   ├── difficulties.yml         # Difficulty level definitions
│   └── tags.yml                 # Problem tag categories
├── scripts/                     # Automation and utility scripts
│   ├── generate_readme.py       # Auto-generate README content
│   ├── update_badges.py         # Update repository badges
│   └── update_badges.sh         # Badge update automation
├── .github/workflows/           # CI/CD automation
│   ├── code-health-*.yml        # Comprehensive testing workflows
│   ├── linter-*.yml             # Code quality workflows
│   ├── presubmit-*.yml          # Pre-merge validation
│   └── update-badges.yml        # Automated badge updates
├── Makefile                     # Build and test automation
├── requirements.txt             # Python dependencies
├── .clang-format                # C++ code formatting rules
└── .clang-tidy                  # C++ linting configuration

🛠️ Technologies & Tools

Languages & Standards

  • C++: C++20 with modern features and best practices
  • Python: Python 3.x with type hints and modern syntax

Testing Frameworks

  • C++: Google Test (gtest) for comprehensive unit testing
  • Python: pytest with coverage reporting

Code Quality Tools

  • C++ Formatting: clang-format for consistent code style
  • C++ Linting: clang-tidy for static analysis and best practices
  • Python Formatting: ruff for fast, comprehensive code formatting
  • Python Linting: ruff for linting, import sorting, and code quality

Build & Automation

  • Make: Cross-platform build system with intelligent target detection
  • GitHub Actions: Automated CI/CD with parallel testing and validation

Running Tests

The project includes comprehensive test suites for all solutions with cross-platform support.

🐍 Python Tests

# Run all Python tests with coverage
make test-py:all

# Run tests for a specific problem (e.g., two-sum)
make test-py:two-sum

⚡ C++ Tests

# Run all C++ tests (auto-detects macOS/Linux)
make test-cpp:all

# Run tests for a specific problem (e.g., two-sum)
make test-cpp:two-sum

# Run all tests (both languages)
make test:all

Requirements:

  • macOS: brew install googletest
  • Linux: sudo apt-get install libgtest-dev or build from source

Code Quality

This project maintains high code quality standards through automated tooling and CI/CD integration.

🎨 Formatting & Linting

# Format all code (C++ with clang-format, Python with ruff)
make format

# Lint all code with comprehensive checks
make lint

# Language-specific operations
make format-cpp     # Format C++ files with clang-format
make format-py  # Format Python files with ruff
make lint-cpp       # Lint C++ files with clang-tidy
make lint-py    # Lint Python files with ruff

🔄 Continuous Integration

The project includes a comprehensive CI/CD pipeline:

  • 🔍 Presubmit Checks: Validate code changes before merge

    • Format validation (clang-format, ruff)
    • Linting checks (clang-tidy, ruff)
    • Unit test execution for changed files
  • 🧪 Code Health: Full validation after merge to main

    • Complete test suite execution
    • Cross-platform compatibility testing
    • Coverage reporting
  • 📊 Automated Maintenance:

    • Badge updates reflecting current status
    • PR size labeling for review optimization
    • Workflow status monitoring

All workflows leverage the project's Makefile for consistency across local development and CI environments.

🧮 Algorithms & Data Structures

This repository covers a comprehensive range of algorithmic patterns and data structures commonly found in technical interviews:

Arrays & Hashing

# Title Solution Time Space Difficulty Tag Note
1 Two Sum Python, C++ O(n) O(n) Easy
49 Group Anagrams Python, C++ O(n * k log k) O(n) Medium For C++, the complexity is O(n * k log k), where n is the number of strings and k is the maximum length of a string. But for Python, the complexity is O(n * k) as there is no sorting involved.
217 Contains Duplicate Python, C++ O(n) O(n) Easy
2303 Calculate Amount Paid In Taxes Python, C++ O(n) O(1) Easy

Two Pointers

# Title Solution Time Space Difficulty Tag Note
125 Valid Palindrome Python, C++ O(n) O(1) Easy

Trees

# Title Solution Time Space Difficulty Tag Note
2313 Minimum Flips in Binary Tree to Get Result Python, C++ O(n) O(1) Hard n is the number of nodes in the binary tree.

Backtracking

# Title Solution Time Space Difficulty Tag Note
1087 Brace Expansion Python, C++ O(M^K + M log M) O(M^K) Medium M = max choices per brace set, K = number of brace sets. M^K for generating combinations, M log M for sorting.

Graphs

# Title Solution Time Space Difficulty Tag Note
399 Evaluate Division Python, C++ O(N + M) O(N) Medium N = number of equations, M = number of queries.