Skip to content

dmaman86/algo-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AlgoExpert Solutions

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.

πŸ“– Table of Contents

Summary of Problems

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

Difficulty Legend

Emoji Difficulty
🟒 Easy
🟑 Medium
πŸ”΄ Hard
⚫ Very hard

Arrays Problems

# 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

Binary search trees Problems

# 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

Binary trees Problems

# 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

Famous algorithms Problems

# 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

Graphs Problems

# 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

Greedy algorithms Problems

# 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

Dynamic programming Problems

# 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

Quick Start

πŸ“Œ Clone the repository:

git clone https://github.com/dmaman86/algo-solutions.git && cd algo-solutions

πŸ”Ή Install dependencies:

make setup

πŸ§ͺ Run all tests:

make test

How To Use This Project (Workflow)

1. Set Up the Environment:

Run the following command based on your operating system:

make setup

What does make setup do?:

  • 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.
  • Sets up the C++ build structure using CMake.
  • Ensures your Python version is 3.8 or higher.

2. Run Tests:

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

3. Run Tests with Visualizations (Python only):

Some Python tests may generate graphs or visual outputs. To enable them, use:

make visualize

4. Clean the project:

To remove compiled files and Python cache (__pycache__), use:

make clean

This will delete:

  • Build files (build/).
  • Python cache files (__pycache__).

5. Help:

To view all available Makefile rules, use:

make help

This 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 files

Project Structure

This 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.

Folder Breakdown:

.
β”œβ”€β”€ 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

Notes:

  • 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

About

My growing collection of solutions to algorithmic problems from AlgoExpert, with test cases and optimizations to improve problem-solving skills.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors