Skip to content

LeetCohort is a free Python coding platform where you can solve problems, earn points, and compete on the leaderboard. Built for the Axiom YSWS HackClub program

License

Notifications You must be signed in to change notification settings

Rexaintreal/LeetCohort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetCohort Logo

LeetCohort

Free Python coding practice platform built for Axiom YSWS

GitHub Axiom Hackatime Flask JavaScript TailwindCSS


About

LeetCohort is a free coding practice platform focused on Python Solve problems, earn points, and compete on the leaderboard. Built as part of the Axiom YSWS (HackClub) program.


Live Demo

Try it out at LeetCohort and Demo Video DEMO google drive link


Features

  • Solve Python coding problems across multiple difficulty levels
  • Run code against sample test cases before submission
  • Submit solutions and get instant feedback
  • Earn points for solving problems
  • Compete on the global leaderboard with other users
  • Track your progress and solved problems with detailed charts
  • OAuth login with Google, GitHub, and Hack Club
  • Profile customization with picture upload
  • Export your data or delete your account anytime

Tech Stack

Frontend

  • HTML
  • Tailwind CSS via CDN
  • Vanilla JavaScript

Backend

  • Flask
  • SQLite for problem storage
  • Firebase Firestore for user data
  • Firebase Authentication
  • HackClub and GitHub OAuth ()

Hosting

  • PythonAnywhere for free hosting

Code Execution

  • Piston API for secure code execution

How It Works

Problem Solving Flow

  1. Browse Problems - View coding challenges filtered by difficulty and topics
  2. Write Solution - Use the code editor to write your Python solution
  3. Test Code - Run against sample test cases to verify basic functionality
  4. Submit - Your code runs against all test cases including hidden ones
  5. Get Feedback - Instant results showing which test cases passed or failed
  6. Earn Points - Successfully passing all test cases awards points based on difficulty

Behind the Scenes

  • Your code gets wrapped with a test harness and sent to Piston API for execution
  • Multiple test cases run in parallel for faster results
  • Output is compared with expected results using smart comparison logic
  • Some problems check time complexity to ensure efficient solutions
  • All execution happens in isolated sandboxed containers for security
  • Points and solved problems sync to your profile automatically

Scoring System

  • Easy problems: 10-20 points
  • Medium problems: 30-40 points
  • Hard problems: 50+ points
  • Each test case within a problem can award partial points
  • Leaderboard ranks users by total points earned
  • Points are given based on various things such as difficulty, time complexity, hints etc.

Project Structure

LeetCohort/
├── app.py                  # Main Flask application
├── execution.py            # Code execution logic
├── requirements.txt        # Python dependencies
├── db/
│   ├── createDb.py        # Database schema creation
│   ├── insertDb.py        # Problem insertion script
│   ├── problems.json      # Problem data
│   └── problems.db        # SQLite database
├── static/
│   ├── assets/            # Images and logos
│   ├── css/               # Stylesheets
│   ├── js/                # JavaScript files
│   └── uploads/           # User uploaded profile pictures
└── templates/             # HTML templates

Setup and Installation

Prerequisites

  • Python 3.12 or higher (I used 3.12.10)
  • pip for installing packages
  • Firebase project with Firestore and Authentication enabled
  • If you want to use HackClub or GitHub OAuth please refer to their respective Docs (Almost same as Google)

Installation Steps

  1. Clone the repository
   git clone https://github.com/Rexaintreal/LeetCohort.git
   cd LeetCohort
  1. Create a virtual environment (Recommended)

    Windows:

   python -m venv venv
   .\venv\Scripts\activate

macOS / Linux:

   python3 -m venv venv
   source venv/bin/activate
  1. Install dependencies
   pip install -r requirements.txt
  1. Set up environment variables

    Create a .env file in the root directory with:

   FLASK_SECRET_KEY=your_secret_key
   
   FIREBASE_API_KEY=your_firebase_api_key
   FIREBASE_AUTH_DOMAIN=your_project.firebaseapp.com
   FIREBASE_PROJECT_ID=your_project_id
   FIREBASE_STORAGE_BUCKET=your_project.appspot.com
   FIREBASE_MESSAGING_SENDER_ID=your_sender_id
   FIREBASE_APP_ID=your_app_id
   FIREBASE_MEASUREMENT_ID=your_measurement_id
   
   HACKCLUB_CLIENT_ID=your_hackclub_client_id
   HACKCLUB_CLIENT_SECRET=your_hackclub_secret
   HACKCLUB_REDIRECT_URI=http://localhost:5000/auth/hackclub/callback
   
   GITHUB_CLIENT_ID=your_github_client_id
   GITHUB_CLIENT_SECRET=your_github_secret
   GITHUB_REDIRECT_URI=http://localhost:5000/auth/github/callback
   
   [email protected]
   MAIL_PASSWORD=your_app_password
   [email protected]
  1. Add Firebase Admin SDK

    Download your Firebase Admin SDK JSON file and save it as firebase-admin-sdk.json in the root directory

  2. Initialize the database

   cd db
   python createDb.py
   python insertDb.py
   cd ..
  1. Run the application
   python app.py
  1. Open your browser and go to http://127.0.0.1:5000 or localhost:500 if you've specified that in the OAuth Urls

Database Schema

Problems Table

CREATE TABLE problems (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    slug TEXT UNIQUE NOT NULL,
    description TEXT NOT NULL,
    input_format TEXT,
    output_format TEXT,
    difficulty TEXT CHECK(difficulty IN ('Easy', 'Medium', 'Hard')),
    topic_tags TEXT,
    company_tags TEXT,
    constraints TEXT,
    boilerplate_code TEXT,
    time_complexity TEXT,
    space_complexity TEXT,
    points INTEGER DEFAULT 10,
    order_matters INTEGER DEFAULT 1,
    check_complexity INTEGER DEFAULT 0,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Test Cases Table

CREATE TABLE test_cases (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    problem_id INTEGER NOT NULL,
    input TEXT,
    expected_output TEXT,
    input_json TEXT,
    expected_output_json TEXT,
    is_sample INTEGER DEFAULT 0,
    explanation TEXT,
    points INTEGER DEFAULT 10,
    display_order INTEGER DEFAULT 0,
    FOREIGN KEY (problem_id) REFERENCES problems(id) ON DELETE CASCADE
);

Hints Table

CREATE TABLE hints (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    problem_id INTEGER NOT NULL,
    hint TEXT NOT NULL,
    display_order INTEGER DEFAULT 0,
    FOREIGN KEY (problem_id) REFERENCES problems(id) ON DELETE CASCADE
);

Features in Detail

Code Execution

  • Sample test cases visible before submission
  • Hidden test cases for actual submission
  • Time complexity validation for certain problems
  • Parallel test case execution for faster results

Scoring System

  • Each test case awards points when passed
  • Problems have difficulty based total points
  • Leaderboard ranks users by total points earned
  • Track solved problems by difficulty level

User Accounts

  • OAuth login via Google, GitHub, or Hack Club
  • Customizable profile with name and picture (we've a cute default avatar for HackClub users)
  • View solved problems and statistics
  • Export all your data as JSON format
  • Delete account and all associated data easily

Credits

Landing Page Background - uiverse.io/1k24bytes/hot-cow-99

Problems - GeeksforGeeks DSA Interview Questions

Avatars - Pinterest and Orpheus from Hack Club Summer of Making


Other Projects


License

MIT LICENSE


Author

Built by Saurabh Tiwari

About

LeetCohort is a free Python coding platform where you can solve problems, earn points, and compete on the leaderboard. Built for the Axiom YSWS HackClub program

Topics

Resources

License

Stars

Watchers

Forks