Crates.io | leetcode-runner-cli |
lib.rs | leetcode-runner-cli |
version | 0.2.71 |
source | src |
created_at | 2023-07-04 12:23:39.321951 |
updated_at | 2023-07-04 12:49:29.920389 |
description | A tool to execute and submit leetcode problems from the command line |
homepage | |
repository | https://github.com/dvishal485/leetcode-runner-cli |
max_upload_size | |
id | 907936 |
size | 287,637 |
Executes leetcode testcases and submits your solution through CLI interface
Disclaimer : This is not an official Leetcode tool. I am not affiliated with Leetcode in any way. This tool is not endorsed by leetcode.
If you have Cargo installed on your system then you can install the tool using the following command.
cargo install leetcode-runner-cli
Go to the Releases section and download the appropriate binary for your system.
Place the binary in appropriate location and add the location in your PATH environment variable.
Install rust from here to compile the source code.
Clone the repository and move to the repository directory.
git clone https://github.com/dvishal485/leetcode-runner-cli.git
cd leetcode-runner-cli
Compile and install the binary.
cargo install --path .
Depending on your platform you may need to install certain tools to be able to compile successfully.
apt-get install pkg-config openssl-dev -y
to be able to compile the program successfully.Setup environment variable LC_COOKIE
with your leetcode session cookie. You may search on internet to know how to setup an environment variable on your system.
You can get your session cookie by logging in to leetcode and inspecting the cookie from Request headers in your browser's developer tools.
Make sure to put your cookie in double quotes.
export LC_COOKIE="csrftoken=abcdefgh;LEETCODE_SESSION=ijklmnopqrstuvwxyz;"
Execute the tool and verify your authentication.
leetcode-runner-cli -a
leetcode-runner-cli [COMMAND] [OPTIONS <option>]
Commands | Description | Arguments |
---|---|---|
-h, --help |
Prints help information | - |
-V, --version |
Prints version information | - |
-a, auth |
Authenticate with leetcode | - |
-d, daily |
Fetch daily challenge question | - |
-q, question |
Question title / url to fetch | [QUESTION_NAME] (required) |
-r, run |
Execute file with default/specified testcases | -f [FILE] -t [TESTCASE_FILE] |
-s, submit |
Submit solution after passing testcases | -f [FILE] |
-fs, fast-submit |
Submit solution without checking for testcase | -f [FILE] |
-p, pack |
Pack your solution and question in a directory | -f [FILE] |
You can always look into a commands usage by passing --help
.
If you fetch the question from the CLI (using -d
or -q
), then tool will automatically add the required changes in the boiler plate code.
But if you are using your own code, then you need to make the following changes :
The file you submit to leetcode shouldn't have driver code like main function or struct definition. But no need to manually remove it. The tool will automatically remove the driver code and submit the solution to leetcode. All you need to do is put the delimiters #LCSTART
and #LCEND
in your solution file in comments, and place leetcode problem link anywhere in the file.
For example :
struct Solution;
// #LCSTART
impl Solution {
pub fn two_sum(nums: Vec<i32>, target: i32) -> Vec<i32> {
// real magic here
}
} // #LCEND https://leetcode.com/problems/two-sum/
fn main() {
// can have anything which may assist you
}
The file name need not to be specified explicitly with --file
or -f
as it is an optional field. Check out Note below for more information
Fetch question koko-eating-bananas
leetcode-runner-cli -q koko-eating-bananas
OR
leetcode-runner-cli -q https://leetcode.com/problems/koko-eating-bananas/
Run src/main.rs with default testcases for question koko-eating-bananas
leetcode-runner-cli -r --file /src/main.rs
Run src/main.rs with custom testcase file
leetcode-runner-cli -r -t testcase.txt --file /src/main.rs
Submit src/main.rs to leetcode
leetcode-runner-cli -s --file /src/main.rs
Note : This will first execute the default testcases (or the specified testcases if given) and then submit the solution to leetcode only if the testcases pass as a preventive measure to avoid submitting wrong solution.
Submit src/main.rs to leetcode without running testcases
leetcode-runner-cli -fs -f /src/main.rs
Pack your code and question into a directory to maintain your progress or upload on Git
leetcode-runner-cli -p --file /src/main.rs
main
or the first file it finds in case there is no main
file.So, in the above examples, you can simply do cd ./src
and then run the following commands :
leetcode-runner-cli -r -t testcase.txt
leetcode-runner-cli -r
leetcode-runner-cli -s
leetcode-runner-cli -fs
leetcode-runner-cli -p
This is a generic module that can be used to run any language. It only needs a mapping to the language
on leetcode and extension
of the file.
Currently, the following languages are added by default : Rust, Python3, Cpp, Java, C, Javascript, Go, Kotlin, Swift, Typescript, Csharp, Ruby, Scala, PHP, Racket, Erlang, Elixir, Dart.
More languages can be added manually as per requirement by changing enum in the src/file_parser/language.rs
file.