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
โโโ problems/ # Problem solutions organized by name
โ โโโ defs.bzl # Starlark macro for defining problem targets
โ โโโ two_sum/ # Individual problem directories
โ โ โโโ BUILD.bazel # Problem target definitions
โ โ โโโ 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
โ โโโ ...
โโโ common/ # Shared data structures (e.g. TreeNode)
โโโ config/ # Global configuration files
โ โโโ difficulties.yml # Difficulty level definitions
โ โโโ tags.yml # Problem tag categories
โโโ scripts/ # Automation and utility scripts
โ โโโ format.sh # Code formatting (C++ & Python)
โ โโโ lint.sh # Code linting (C++ & Python)
โ โโโ install_hooks.sh # Git hooks installer
โ โโโ uninstall_hooks.sh # Git hooks uninstaller
โ โโโ generate_readme.py # Auto-generate README content
โ โโโ update_badges.py # Update repository badges
โ โโโ update_badges.sh # Badge update automation
โโโ tools/ # Build tools & test runners
โโโ .github/workflows/ # CI/CD automation
โ โโโ cpp-test.yml # C++ Bazel testing
โ โโโ python-test.yml # Python Bazel testing
โ โโโ cpp-lint.yml # C++ clang-tidy and clang-format
โ โโโ python-lint.yml # Python ruff lint and format
โ โโโ pr-size-labeler.yml # PR size labeling
โโโ MODULE.bazel # External dependency management (Bzlmod)
โโโ BUILD.bazel # Root package definition
โโโ .bazelrc # Bazel compiler flags & options
โโโ requirements.txt # Python dependencies
โโโ requirements_lock.txt # Pinned dependencies for rules_python
โโโ .clang-format # C++ code formatting rules
โโโ .clang-tidy # C++ linting configuration
- C++: C++20 with modern features and strict compiler warnings (
-std=c++20 -Wall -Wextra -Wpedantic) - Python: Python 3.14 with type hints and modern syntax
- C++: Google Test (
googletest@1.18.0.bcr.1) hermetically managed via Bazel Bzlmod - Python: pytest hermetically managed via
rules_python
- C++ Formatting:
clang-formatfor consistent code style - C++ Linting:
clang-tidyfor static analysis and best practices - Python Formatting & Linting:
rufffor fast formatting and linting
- Bazel: Multi-language, hermetic build and test system with sandboxed execution and transitive caching
- GitHub Actions: Automated CI/CD running native Bazel test targets
All test targets run sandboxed and in parallel with action caching. No system installation of Google Test or CMake is required.
# Run all tests (both C++ and Python) across the entire repo
bazel test //problems/...
# Run all tests for a specific problem (both languages)
bazel test //problems/two_sum:test
# Run only C++ tests
bazel test //problems/two_sum:cc_test # for a specific problem
bazel test --test_tag_filters=cc //problems/... # for all problems
# Run only Python tests
bazel test //problems/two_sum:py_test # for a specific problem
bazel test --test_tag_filters=py //problems/... # for all problemsThis project maintains high code quality standards through automated tooling:
# Format code (C++ with clang-format, Python with ruff)
./scripts/format.sh # format both
./scripts/format.sh cpp # format C++ only
./scripts/format.sh py # format Python only
# Lint code (C++ with clang-tidy, Python with ruff)
./scripts/lint.sh # lint both
./scripts/lint.sh cpp # lint C++ only
./scripts/lint.sh py # lint Python onlyInstall the pre-commit hook to automatically format, lint, update badges, and run tests before committing:
./scripts/install_hooks.sh# Regenerate README from problem configurations
bazel run //scripts:generate_readme
# Update README badges with current solution counts
bazel run //scripts:update_badges
# or: ./scripts/update_badges.sh
# Clean build artifacts
bazel cleanThe GitHub Actions CI pipeline runs 4 focused workflows on both pull requests and pushes to main:
- โก C++ / Test (
cpp-test.yml): Parallel sandboxed GoogleTest execution via Bazel - ๐ Python / Test (
python-test.yml): Parallel sandboxed pytest execution via Bazel - ๐ C++ / Lint (
cpp-lint.yml): Static analysis (clang-tidy) and format enforcement (clang-format) - ๐ Python / Lint (
python-lint.yml): Ruff linting and format enforcement
This repository covers a comprehensive range of algorithmic patterns and data structures commonly found in technical interviews:
- Array / String
- Two Pointers
- Sliding Window
- Matrix
- Hashmap
- Intervals
- Stack
- Linked List
- Binary Tree General
- Binary Tree BFS
- Binary Search Tree
- Graph General
- Graph BFS
- Trie
- Backtracking
- Divide & Conquer
- Kadane's Algorithm
- Binary Search
- Heap
- Bit Manipulation
- Math
- 1D DP
- Multidimensional DP
| # | Title | Difficulty | Approach | Solution | Time | Space | Note |
|---|---|---|---|---|---|---|---|
| 6 | Zigzag Conversion | Medium | Row Buckets | Python, C++ | O(n) | O(n) | |
| Math | Python, C++ | O(n) | O(1) | ||||
| 12 | Integer to Roman | Medium | Math | Python, C++ | O(1) | O(1) | |
| 13 | Roman to Integer | Easy | Math | Python, C++ | O(n) | O(1) | |
| 14 | Longest Common Prefix | Easy | Vertical Scanning | Python, C++ | O(n * m) | O(1) | |
| Horizontal Scanning | Python, C++ | O(n * m) | O(1) | ||||
| Min / Max Lexicographical | Python, C++ | O(n * m) | O(1) | ||||
| Trie | Python, C++ | O(n * m) | O(n * m) | ||||
| 26 | Remove Duplicates from Sorted Array | Easy | Two Pointers | Python, C++ | O(n) | O(1) | |
| 27 | Remove Element | Easy | Two Pointers | Python, C++ | O(n) | O(1) | |
| 28 | Find the Index of the First Occurrence in a String | Easy | Brute Force | Python, C++ | O(n * m) | O(1) | |
| Knuth-Morris-Pratt (KMP) Algorithm | Python, C++ | O(n + m) | O(m) | ||||
| 42 | Trapping Rain Water | Hard | Brute Force | Python, C++ | O(n^2) | O(1) | |
| Dynamic Programming | Python, C++ | O(n) | O(n) | ||||
| Monotonic Stack | Python, C++ | O(n) | O(n) | ||||
| Two Pointers | Python, C++ | O(n) | O(1) | ||||
| 45 | Jump Game II | Medium | Dynamic Programming | Python, C++ | O(n^2) | O(n) | |
| Greedy | Python, C++ | O(n) | O(1) | ||||
| 55 | Jump Game | Medium | Dynamic Programming | Python, C++ | O(n^2) | O(n) | |
| Greedy | Python, C++ | O(n) | O(1) | ||||
| 58 | Length of Last Word | Easy | String Traversal | Python, C++ | O(n) | O(1) | |
| 68 | Text Justification | Hard | Greedy | Python, C++ | O(k * maxWidth), where k is the number of lines | O(maxWidth) | |
| 80 | Remove Duplicates from Sorted Array II | Medium | Two Pointers | Python, C++ | O(n) | O(1) | |
| 88 | Merge Sorted Array | Easy | Two Pointers | Python, C++ | O(m + n) | O(1) | |
| 121 | Best Time to Buy and Sell Stock | Easy | Dynamic Programming | Python, C++ | O(n) | O(1) | |
| Greedy | Python, C++ | O(n) | O(1) | ||||
| 122 | Best Time to Buy and Sell Stock II | Medium | Dynamic Programming | Python, C++ | O(n) | O(1) | |
| Greedy | Python, C++ | O(n) | O(1) | ||||
| 134 | Gas Station | Medium | Greedy | Python, C++ | O(n) | O(1) | |
| 135 | Candy | Hard | Greedy (Two Passes) | Python, C++ | O(n) | O(n) | |
| 151 | Reverse Words in a String | Medium | In-Place Reversal | Python, C++ | O(n) | O(1) | |
| 169 | Majority Element | Easy | Boyer-Moore Majority Vote Algorithm | Python, C++ | O(n) | O(1) | |
| 189 | Rotate Array | Medium | Repeated Shift | Python, C++ | O(nk) | O(1) | |
| Extra Space | Python, C++ | O(n) | O(n) | ||||
| Reversal | Python, C++ | O(n) | O(1) | ||||
| 238 | Product of Array Except Self | Medium | Prefix Sum | Python, C++ | O(n) | O(1) | |
| 274 | H-Index | Medium | Sorting | Python, C++ | O(n log n) | O(1) | |
| Counting Sort | Python, C++ | O(n) | O(n) | ||||
| 380 | Insert Delete GetRandom O(1) | Medium | Array & Hashmap | Python, C++ | O(1) | O(n) |
| # | Title | Difficulty | Approach | Solution | Time | Space | Note |
|---|---|---|---|---|---|---|---|
| 11 | Container With Most Water | Medium | Two Pointers | Python, C++ | O(n) | O(1) | |
| 15 | 3Sum | Medium | Sorting & Two Pointers | Python, C++ | O(n^2) | O(1) | You have to avoid duplicates without using sets. |
| 125 | Valid Palindrome | Easy | Two Pointers | Python, C++ | O(n) | O(1) | |
| 167 | Two Sum II - Input Array Is Sorted | Medium | Two Pointers | Python, C++ | O(n) | O(1) | |
| 392 | Is Subsequence | Easy | Two Pointers | Python, C++ | O(n) | O(1) |
| # | Title | Difficulty | Approach | Solution | Time | Space | Note |
|---|---|---|---|---|---|---|---|
| 1 | Two Sum | Easy | Brute Force | Python, C++ | O(n^2) | O(1) | |
| Hash Map | Python, C++ | O(n) | O(n) | ||||
| 49 | Group Anagrams | Medium | โ | Python, C++ | O(n * k log k) | O(n) | 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. |
| # | Title | Difficulty | Approach | Solution | Time | Space | Note |
|---|---|---|---|---|---|---|---|
| 399 | Evaluate Division | Medium | โ | Python, C++ | O(N + M) | O(N) | N = number of equations, M = number of queries. |