This repository contains solutions to a wide range of algorithmic problems, categorized by topics such as Arrays, Binary Trees, Graphs, Dynamic Programming, and more. Each problem is solved in multiple programming languages (JavaScript, Python, and C++) and includes unit tests for verification.
- Summary of Problems
- π Quick Start
- π§ How To Use This Project (Workflow)
- π Project Structure
- πΉ Notes
| Topic | Number of Problems |
|---|---|
| Arrays | 12 |
| Binary Search Trees | 4 |
| Binary Trees | 6 |
| Famous Algorithms | 6 |
| Graphs | 6 |
| Greedy Algorithms | 6 |
| Dynamic Programming | 4 |
| --------------------- | -------------------- |
| Total | 44 |
| Emoji | Difficulty |
|---|---|
| π’ | Easy |
| π‘ | Medium |
| π΄ | Hard |
| β« | Very hard |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Sorted Squared Array | π’ |
Js |
| 2 | Tournament Winner | π’ |
Js, Cpp |
| 3 | Two Number Sum | π’ |
Js |
| 4 | Validate Subsequence | π’ |
Js, Python |
| 5 | Four Number Sum | π΄ |
Cpp, Js |
| 6 | Subarray Sort | π΄ |
Cpp, Js, Python |
| 7 | Count Squares | π΄ |
Js, Python, Cpp |
| 8 | Zigzag Traverse | π΄ |
Js, Python, Cpp |
| 9 | Min Rewards | π΄ |
Js, Python, Cpp |
| 10 | Apartment Hunting | β« |
Js, Python, Cpp |
| 11 | Line Through Points | β« |
Js, Python, Cpp |
| 12 | Calendar Matching | β« |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Repair Bst | π΄ |
Js, Python, Cpp |
| 2 | Same Bsts | π΄ |
Js, Python, Cpp |
| 3 | Validate Three Nodes | π΄ |
Js, Python, Cpp |
| 4 | Right Smaller Than | β« |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Find Nodes Distance K | π΄ |
Js, Python, Cpp |
| 2 | Max Path Sum In Binary Tree | π΄ |
Js, Python, Cpp |
| 3 | Compare Leaf Traversal | β« |
Js, Python, Cpp |
| 4 | Right Sibling Tree | β« |
Js, Python, Cpp |
| 5 | Flatten Binary Tree | β« |
Js, Python, Cpp |
| 6 | All Kinds Of Node Depths | β« |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Kadanes Algorithm | π‘ |
Js, Cpp |
| 2 | Dijkstras Algorithm | π΄ |
Js, Python, Cpp |
| 3 | Kruskals Algorithm | π΄ |
Js, Python, Cpp |
| 4 | Prims Algorithm | π΄ |
Js, Python, Cpp |
| 5 | Topological Sort | π΄ |
Js, Python, Cpp |
| 6 | Astar Algorithm | β« |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Minimum Passes Of Matrix | π‘ |
Js, Python, Cpp |
| 2 | Youngest Common Ancestor | π‘ |
Js, Python, Cpp |
| 3 | Cycle In Graph | π‘ |
Js, Python, Cpp |
| 4 | Boggle Board | π΄ |
Js, Python, Cpp |
| 5 | Airport Connections | β« |
Js, Python, Cpp |
| 6 | Detect Arbitrage | β« |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Optimal Freelancing | π’ |
Js, Python, Cpp |
| 2 | Tandem Bicycle | π’ |
Js, Python, Cpp |
| 3 | Class Photos | π’ |
Js, Python, Cpp |
| 4 | Minimum Waiting Time | π’ |
Js, Python, Cpp |
| 5 | Task Assignment | π‘ |
Js, Python, Cpp |
| 6 | Valid Starting City | π‘ |
Js, Python, Cpp |
| # | Problem | Difficulty | Languages |
|---|---|---|---|
| 1 | Maximum Sum Submatrix | π΄ |
Js, Python, Cpp |
| 2 | Knapsack Problem | π΄ |
Js, Python, Cpp |
| 3 | Max Profit With K Transactions | β« |
Js, Python, Cpp |
| 4 | Longest Increasing Subsequence | β« |
Js, Python, Cpp |
π Clone the repository:
git clone https://github.com/dmaman86/algo-solutions.git && cd algo-solutionsπΉ Install dependencies:
make setupπ§ͺ Run all tests:
make testRun the following command based on your operating system:
make setup- Installs Python dependencies from
requirements.txt. - Installs Google Test (gtest) and nlohmann/json depending your operating system:
- macOS: Uses
brew. - Linux: Uses
apt-get. - Windows: Uses
vcpkg.
- macOS: Uses
- Sets up the C++ build structure using
CMake. - Ensures your Python version is
3.8or higher.
You can run tests for each language individually or all at once.
-
Run all tests (JavaScript, Python and C++):
make test -
Run JavaScript tests only:
make test-js
-
Run Python tests only:
make test-python
-
Run C++ tests only:
make test-cpp
Some Python tests may generate graphs or visual outputs. To enable them, use:
make visualizeTo remove compiled files and Python cache (__pycache__), use:
make cleanThis will delete:
- Build files (
build/). - Python cache files (
__pycache__).
To view all available Makefile rules, use:
make helpThis will display:
make setup # Install all dependencies (Python, C++)
make test # Run all tests, without visualizations
make test-js # Run JavaScript tests with npm
make test-python # Run Python tests with pytest
make test-cpp # Run C++ tests with CMake
make visualize # Run Python tests and generate visualizations
make clean # Clean temporary filesThis repository is structured as follows:
- problems/ β Algorithmic challenges, organized by category.
- tests/ β Unit tests for JavaScript, C++, and Python solutions.
- scripts/ β Utility scripts (e.g., updating the README).
- test_cases/ β JSON-based test cases for automated validation.
- makefile β Automates testing, visualization, and cleanup tasks.
.
βββ CMakeLists.txt # Main configuration file for C++ tests
βββ README.md # Project documentation and usage instructions
βββ babel.config.json # Babel configuration for JavaScript tests
βββ jest.config.cjs # Jest configuration file for JavaScript tests
βββ makefile # Automates common tasks (e.g., testing, visualization)
βββ metadata.json # Metadata about problems and their solutions
βββ package-lock.json # Dependency lock file for npm
βββ package.json # Node.js project configuration file
βββ requirements.txt # Python dependencies
βββ problems/ # Solutions to problems, organized by topic
β βββ arrays/ # Array-related problems
β βββ binary_search_trees/ # Binary search tree problems
| βββ binary_trees/ # Binary tree problems
β βββ famous_algorithms/ # Well-known algorithms
β βββ greedy_algorithms/ # Greedy algorithm problems
β βββ dynamic_programming/ # Dynamic programming problems
β βββ graphs/ # Graph-related problems
βββ scripts/ # Utility scripts for project maintenance
β βββ update_readme.py # Updates README with metadata or problem table
βββ tests/ # Contains all test-related files
βββ __tests__/ # JavaScript tests (run with Jest)
β βββ arrays/ # Array-related JavaScript tests
β βββ binary_search_trees/ # Binary search tree JavaScript tests
β βββ binary_trees/ # Binary tree JavaScript tests
β βββ famous_algorithms/ # Well-known algorithm JavaScript tests
| βββ greedy_algorithms/ # Greedy algorithm JavaScript tests
| βββ dynamic_programming/ # Dynamic programming JavaScript tests
β βββ graphs/ # Graph-related JavaScript tests
βββ cpp/ # C++ tests (run with CMake and CTest)
β βββ CMakeLists.txt # Main configuration for all C++ tests
β βββ arrays/ # C++ tests for array problems
β β βββ CMakeLists.txt # Configuration for array-specific tests
β βββ binary_search_trees/ # C++ tests for binary search tree problems
β β βββ CMakeLists.txt # Configuration for binary search tree tests
| βββ binary_trees/ # C++ tests for binary tree problems
β β βββ CMakeLists.txt # Configuration for binary tree tests
β βββ famous_algorithms/ # C++ tests for well-known algorithms
β β βββ CMakeLists.txt # Configuration for famous algorithms tests
β βββ dynamic_programming/ # C++ tests for dynamic programming problems
β β βββ CMakeLists.txt # Configuration for dynamic programming tests
| βββ greedy_algorithms/ # C++ tests for greedy algorithm problems
β β βββ CMakeLists.txt # Configuration for greedy algorithm tests
β βββ graphs/ # C++ tests for graph problems
β β βββ CMakeLists.txt # Configuration for graph-specific tests
β βββ jsontestbase.h # Header for handling JSON-based test cases in C++
βββ python/ # Python tests (run with pytest)
β βββ arrays/ # Python tests for array problems
β βββ binary_search_trees/ # Python tests for binary search tree problems
β βββ binary_trees/ # Python tests for binary tree problems
β βββ conftest.py # Configuration for pytest
β βββ famous_algorithms/ # Python tests for well-known algorithms
β βββ graphs/ # Python tests for graph problems
β βββ greedy_algorithms/ # Python tests for greedy algorithm problems
β βββ dynamic_programming/ # Python tests for dynamic programming problems
β βββ utility.py # Helper functions for Python tests
βββ test_cases/ # JSON test cases for all problems
βββ arrays/ # Test cases for array problems
βββ binary_search_trees/ # Test cases for binary search tree problems
βββ binary_trees/ # Test cases for binary tree problems
βββ famous_algorithms/ # Test cases for well-known algorithms
|ββ greedy_algorithms/ # Test cases for greedy algorithm problems
βββ dynamic_programming/ # Test cases for dynamic programming problems
βββ graphs/ # Test cases for graph problems
- If you're on Windows, ensure you have vcpkg installed.
- If you encounter compatibility issues, check that you have Python 3.8+ installed.
python3 --version
- You can modify or add more tests in the following directories:
- JavaScript:
tests/__tests__ - Python:
tests/python - C++:
tests/cpp - Test Cases:
tests/test_cases
- JavaScript: