Update Aug 26 - Cleaning up github profile very soon. Discovered that though common practice to reuse Leetcode problems, it is against their TOS. To avoid possible confusion I am closing these projects. Archiving.
A comprehensive collection of LeetCode solutions implemented in Rust, featuring multiple algorithmic approaches, detailed explanations, and extensive testing.
- Multiple Approaches: Each problem includes 2-4 different solutions showcasing various algorithmic techniques
- Comprehensive Testing: 15-30+ unit tests per problem covering edge cases, performance, and correctness
- Detailed Documentation: Time/space complexity analysis and algorithm reasoning for every approach
- Production Quality: Clean, idiomatic Rust code with proper error handling
- Educational Focus: Solutions designed to teach different problem-solving strategies
Located in src/solutions/, each file contains:
- Multiple solution approaches (optimal and educational variants)
- Full complexity analysis (Big-O notation)
- Extensive test suites with edge cases
- Standalone
main()functions for quick testing
| Problem | Title | Difficulty | Key Techniques |
|---|---|---|---|
| 1 | Two Sum | Easy | Hash Map, Two Pointers, Brute Force |
| 2 | Add Two Numbers | Medium | Linked List, Math |
| 3 | Longest Substring Without Repeating | Medium | Sliding Window, Hash Set |
| 4 | Median of Two Sorted Arrays | Hard | Binary Search, Divide & Conquer |
| 5 | Longest Palindromic Substring | Medium | Dynamic Programming, Expand Around Center |
| 6 | ZigZag Conversion | Medium | String Manipulation, Math |
| 7 | Reverse Integer | Medium | Math, Overflow Handling |
| 8 | String to Integer (atoi) | Medium | String Parsing, State Machine |
| 9 | Palindrome Number | Easy | Math, Two Pointers |
| 10 | Regular Expression Matching | Hard | Dynamic Programming, Recursion |
| 11 | Container With Most Water | Medium | Two Pointers, Greedy |
| 12 | Integer to Roman | Medium | Math, String Building |
| 13 | Roman to Integer | Easy | Hash Map, String Parsing |
| 14 | Longest Common Prefix | Easy | String, Trie, Binary Search |
| 15 | 3Sum | Medium | Two Pointers, Sorting |
| 16 | 3Sum Closest | Medium | Two Pointers, Sorting |
| 17 | Letter Combinations of Phone Number | Medium | Backtracking, BFS |
| 18 | 4Sum | Medium | Two Pointers, Hash Map |
| 19 | Remove Nth Node From End | Medium | Two Pointers, Linked List |
| 20 | Valid Parentheses | Easy | Stack |
| 21 | Merge Two Sorted Lists | Easy | Linked List, Recursion |
| 22 | Generate Parentheses | Medium | Backtracking, Dynamic Programming |
Additional 80+ problems organized in src/easy/, src/medium/, and src/hard/ directories.
Each solution file can be run standalone:
# Run a specific problem
rustc src/solutions/problem_1_two_sum.rs && ./problem_1_two_sum
# Or use cargo
cargo run --bin problem-selector# Test all solutions
cargo test
# Test specific problem
cargo test problem_20
# Run with output
cargo test -- --nocapturecargo benchEach solution follows a consistent pattern:
//! # Problem Title
//! **Difficulty**: Easy/Medium/Hard
//! **Topics**: Relevant algorithms and data structures
//!
//! ## Problem Statement
//! [Description]
//!
//! ## Approach Analysis
//! Multiple approaches with reasoning
pub struct Solution;
impl Solution {
/// Primary optimal solution
pub fn solve_optimal() -> ReturnType {
// Implementation with detailed comments
}
/// Alternative approaches for learning
pub fn solve_alternative() -> ReturnType {
// Different algorithmic approach
}
}
#[cfg(test)]
mod tests {
// Comprehensive test suite
}
fn main() {
// Standalone execution examples
}- Two Pointers: Problems 11, 15, 16, 18, 19
- Sliding Window: Problem 3
- Dynamic Programming: Problems 5, 10, 22
- Backtracking: Problems 17, 22
- Linked Lists: Problems 2, 19, 21
- Stack: Problem 20
- Binary Search: Problems 4, 14
- Start with Easy problems (1, 9, 13, 14, 20, 21)
- Progress to Medium (2, 3, 5, 6, 7, 8, 11, 12, 15-19, 22)
- Challenge yourself with Hard (4, 10)
- Create a new file in
src/solutions/ - Follow the established pattern with multiple approaches
- Include comprehensive tests
- Update
src/solutions/mod.rs
# Format code
cargo fmt
# Run lints
cargo clippy
# Check documentation
cargo doc --openSolutions are optimized for:
- Time Complexity: Each approach clearly states Big-O complexity
- Space Complexity: Memory usage is analyzed and minimized
- Rust Idioms: Leveraging Rust's ownership system for efficiency
Contributions are welcome! Please ensure:
- Multiple solution approaches are provided
- Comprehensive tests are included
- Documentation follows the established pattern
- Code passes all lints and tests
MIT License - See LICENSE for details
Marvin Tutt
Caia Tech
Built with Rust 🦀 for optimal performance and learning