Skip to content

rameshgitter/Leetcode-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

LeetCode Local Test-Case Generator

License: MIT

A zero-dependency, single-file HTML tool that instantly generates a C++ boilerplate for any LeetCode problem, complete with all example test cases, ready for local development and testing.

Stop wasting precious time during contests setting up files, includes, and main functions. Just paste the page source and get a ready-to-compile C++ file in one click.


Demo

(You should replace this with a GIF of your own tool in action!)


Features

  • Instant Boilerplate: Generates a complete C++ file from a LeetCode problem's page source.
  • Auto Test Cases: Automatically parses and includes all example test cases from the problem description.
  • Contest-Style Environment:
    • Simulates Accepted, Wrong Answer, and Time Limit Exceeded verdicts.
    • Measures and prints the execution time for each test case.
  • Smart Parsing: Intelligently extracts the function signature (name, parameters, return type) from the page's metadata.
  • Helper Utilities: Includes helper functions for parsing common LeetCode input formats (e.g., string "[1,2,3]" to vector<int>).
  • Zero Installation: It's a single leetcoder.html file. No dependencies, no build steps. Just open it in your browser.
  • Competitive Programming Style: Uses <bits/stdc++.h> and using namespace std; for fast and clean coding.

How to Use

Step 1: Save the Tool Download the leetcoder.html file from this repository to your local machine.

Step 2: Open in Browser Double-click the leetcoder.html file to open it in your web browser (Chrome, Firefox, etc.).

Step 3: Get LeetCode Page Source

  1. Navigate to the LeetCode problem you want to solve.
  2. Right-click anywhere on the page and select "View Page Source".
  3. A new tab will open with the page's HTML. Press Ctrl + A to select all text, then Ctrl + C to copy it.

Step 4: Generate the Code

  1. Go back to the leetcoder.html browser tab.
  2. Paste (Ctrl + V) the copied source code into the large text area.
  3. Click the "Generate C++ Boilerplate" button.

Step 5: Compile and Run

  1. Your ready-to-use C++ code will appear at the bottom. Click the "Copy" button.

  2. Paste the code into a new file (e.g., solution.cpp).

  3. Open your terminal, navigate to the file's directory, and run:

    # Compile with C++17 and optimization, then run the executable
    g++ -std=c++17 -O2 solution.cpp -o solution && ./solution

Example Generated Output

For the problem 3578. Count Partitions With Max-Min Difference at Most K, the tool generates the following file:

// Generated by LeetCoder for: Count Partitions With Max-Min Difference at Most K
// Link: https://leetcode.com/problems/count-partitions-with-max-min-difference-at-most-k/

#include <bits/stdc++.h>
using namespace std;

// --- Helper Functions ---
// ... (trim, parseVectorInt, printVector) ...

class Solution {
public:
    int countPartitions(const vector<int>& nums, int k) {
        // Your code here
        
        return 0;
    }
};

// --- Main Function for Local Testing ---
int main() {
    Solution sol;
    const int TIME_LIMIT_MS = 1000; // 1 second

    // --- Test Case 1 ---
    {
        cout << "\n--- Test Case 1 ---" << endl;
        string nums1_str = R"([9,4,1,3,7])";
        vector<int> nums1 = parseVectorInt(nums1_str);
        int k1 = 4;
        int expected1 = 6;

        auto start_time = chrono::high_resolution_clock::now();
        int result = sol.countPartitions(nums1, k1);
        auto end_time = chrono::high_resolution_clock::now();
        auto duration = chrono::duration_cast<chrono::milliseconds>(end_time - start_time);

        cout << "Execution time: " << duration.count() << " ms" << endl;

        if (duration.count() > TIME_LIMIT_MS) {
            cout << "Status: Time Limit Exceeded" << endl;
        } else if (result == expected1) {
            cout << "Status: Accepted" << endl;
        } else {
            cout << "Status: Wrong Answer" << endl;
            cout << "Output:   " << result << endl;
            cout << "Expected: " << expected1 << endl;
        }
    }

    // --- Test Case 2 ---
    {
        // ... (similar structure for the second test case) ...
    }

    return 0;
}

Credits

Made it with the help of Google AI Studio

Idea Inspiration from Siddharth from BIT-Meshra

About

A Parser to generate Boiler plate code for LC problems using their page source

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages