A structured project for practicing and mastering the LeetCode 75 essential coding interview questions in Python.
This repository contains solutions to the LeetCode 75 curated list of essential interview questions, organized by problem type. Each solution includes:
- Clean, well-documented Python code
- Comprehensive test cases
- Time and space complexity analysis (where applicable)
pytho-leetcode-75/
├── src/ # Solution modules
│ ├── array_string/ # Array and String problems
│ ├── two_pointers/ # Two Pointers technique
│ ├── sliding_window/ # Sliding Window problems
│ ├── prefix_sum/ # Prefix Sum problems
│ ├── hash_map/ # Hash Map/Set problems
│ ├── stack/ # Stack problems
│ ├── queue/ # Queue problems
│ ├── linked_list/ # Linked List problems
│ ├── binary_tree/ # Binary Tree - DFS problems
│ ├── binary_tree_bfs/ # Binary Tree - BFS problems
│ ├── binary_search_tree/ # Binary Search Tree problems
│ ├── graph_dfs/ # Graph - DFS problems
│ ├── graph_bfs/ # Graph - BFS problems
│ ├── heap/ # Heap/Priority Queue problems
│ ├── binary_search/ # Binary Search problems
│ ├── backtracking/ # Backtracking problems
│ ├── dp_1d/ # Dynamic Programming - 1D
│ ├── dp_multidimensional/ # Dynamic Programming - Multidimensional
│ ├── bit_manipulation/ # Bit Manipulation problems
│ ├── trie/ # Trie problems
│ ├── intervals/ # Intervals problems
│ └── monotonic_stack/ # Monotonic Stack problems
├── tests/ # Test files
├── requirements.txt # Python dependencies
├── pyproject.toml # Project configuration
├── pytest.ini # Pytest configuration
└── README.md # This file
- Python 3.8 or higher
- pip (Python package installer)
- Clone the repository:
git clone https://github.com/cd155/pytho-leetcode-75.git
cd pytho-leetcode-75- Install dependencies:
pip install -r requirements.txtOr install with development dependencies:
pip install -e ".[dev]"pytestpytest tests/test_merge_strings_alternately.pypytest -vpytest --cov=src tests/Create a new Python file in the appropriate category directory under src/. For example:
# src/array_string/your_problem.py
"""
LeetCode XXXX: Problem Title
Problem description here...
"""
class Solution:
def yourMethod(self, input_param):
"""
Solution description.
Args:
input_param: Description
Returns:
Description of return value
"""
# Your implementation here
passCreate a test file in the tests/ directory:
# tests/test_your_problem.py
"""
Tests for LeetCode XXXX: Problem Title
"""
import pytest
import sys
from pathlib import Path
# Add src directory to path
src_path = Path(__file__).parent.parent / "src"
sys.path.insert(0, str(src_path))
from category.your_problem import Solution
class TestYourProblem:
"""Test cases for your problem"""
def setup_method(self):
"""Setup test fixtures"""
self.solution = Solution()
def test_case_1(self):
"""Test description"""
assert self.solution.yourMethod(input) == expected_output
def test_case_2(self):
"""Test description"""
assert self.solution.yourMethod(input) == expected_outputpytest tests/test_your_problem.py -vThe LeetCode 75 problems are organized into the following categories:
- Array / String - Basic array and string manipulation
- Two Pointers - Problems using two pointer technique
- Sliding Window - Window-based array/string problems
- Prefix Sum - Cumulative sum techniques
- Hash Map / Set - Hash table based problems
- Stack - Stack data structure problems
- Queue - Queue data structure problems
- Linked List - Linked list manipulation
- Binary Tree - DFS - Tree traversal with DFS
- Binary Tree - BFS - Tree traversal with BFS
- Binary Search Tree - BST specific problems
- Graphs - DFS - Graph traversal with DFS
- Graphs - BFS - Graph traversal with BFS
- Heap / Priority Queue - Heap-based problems
- Binary Search - Binary search algorithm
- Backtracking - Backtracking technique
- DP - 1D - One-dimensional dynamic programming
- DP - Multidimensional - Multi-dimensional DP
- Bit Manipulation - Bitwise operations
- Trie - Trie data structure
- Intervals - Interval-based problems
- Monotonic Stack - Monotonic stack technique
See src/array_string/merge_strings_alternately.py for an example solution with:
- Detailed problem description
- Clean implementation
- Type hints
- Comprehensive docstrings
And tests/test_merge_strings_alternately.py for example test cases.
Feel free to add more solutions or improve existing ones! Make sure to:
- Follow the existing code structure
- Add comprehensive test cases
- Include docstrings and comments
- Run tests before committing
This project is for educational purposes. All LeetCode problems are property of LeetCode.
Happy Coding! 🚀