Skip to content

comoyun/cheatcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CheatCode

About

This repository contains solutions to LeetCode problems I've solved as part of my preparation for interviews with FAANG (Facebook, Amazon, Apple, Netflix, Google) and other tech companies. The goal is to document my progress and learn from the solutions shared by the community.

File Tree

Each solution is stored in its own folder inside /solutions/. Each folder contains multiple files, each representing a different way to solve the same problem in variety of languages.

solutions/
  0001-two-sum/
    β”œβ”€ brute-force.c
    β”œβ”€ hashmap.c
    β”œβ”€ backtrack.c
    β”œβ”€ backtrack.js
    β”œβ”€ two-pointers.py
    └─ metadata.json

metadata.json includes the problem ID, title, tags, difficulty, and a link to the LeetCode problem (later used for analysis, parsing). Example:

{
    "id": 1,
    "title": "Two Sum",
    "difficulty": "Easy",
    "tags": ["hash-table", "array", "brute-force", "two-pointers"],
    "link": "https://leetcode.com/problems/two-sum/description/"
}

Files and folders are named using kebab-case (e.g., brute-force.js, two-pointers.py). Each solution file starts with a single-line comment declaring time and space complexity, like:

// time: O(n)
// space: O(n)

The comment style (//, #, etc.) is automatically chosen based on the language -- if you use create-solution.js utility function. No need for a title in the comment as the filename already makes the approach obvious.

Utilities

I usually work in the terminal, so I made some CLI tools to make things easier. They're all in the /utils/ folder. You can run them from the project root using npm run <script>. We have the following utility scripts:

  • create-problem: makes a new folder in /solutions/ with starter files

Commit Format

We enforce strict commit naming. Use the following format:

solve: 0001 (js)       # New solution
fix: handle edge case  # Fix an error
perf: optimize logic   # Improve time/space complexity
docs: update readme    # Documentation only
chore: update deps     # Maintenance, dependencies
style: reformat code   # Code style changes
refactor: simplify     # No behavior change

Run npm install to install Commitizen. It reads this config to enforce the format. Use git cz to commit with the correct format automatically.

Contributing

Want to contribute? Great. Please follow these rules:

  1. Star the repo
  2. Strictly follow file and folder naming conventions.
  3. Include the header comment in all solution files.
  4. Update or add metadata.json. You can use utility functions to help with this.
  5. Write clean, readable code.

Note that if you are not sure about time and space complexity of your solution, you can take advantage of "Analyze Complexity" feature on LeetCode:

image

Disclaimer

This repository is shared for collaboration and learning. Copying and pasting code directly without understanding it is discouraged. Use these solutions as references and focus on understanding the reasoning behind each implementation.

About

Easily lookup LeetCode solutions! πŸ”

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks