LeetCode Helper is a full-stack application that helps users solve LeetCode problems using various GenAI providers. The application consists of a Go (Gin-based) backend API and an AstroJS frontend. Users can input LeetCode problems, select their preferred programming language and AI provider, and receive structured solutions with explanations, code, and hints.
The application follows a clean, modular architecture:
- Provider Abstraction: Generic interface for multiple AI providers
- API Endpoints: RESTful endpoints for solving problems and listing providers
- Per-Request API Key Handling: API keys are passed with each request, not stored on the server
- React Components: UI components for input, output, and API key management
- Local Storage: Secure storage of API keys in the browser
- Responsive Design: Works on both desktop and mobile devices
- Go 1.23 or higher
- Node.js 16 or higher
- npm or yarn
- Clone the repository
- Navigate to the backend directory:
cd leetcode-helper/backend
- Install Go dependencies:
go mod tidy
- Run the backend server:
The server will start on port 8080.
go run main.go
- Navigate to the frontend directory:
cd leetcode-helper/frontend
- Install dependencies:
npm install
- Run the development server:
The frontend will be available at http://localhost:3000.
npm run dev
- Open the application in your browser
- Enter a LeetCode problem in the text area
- Select your preferred programming language and experience level
- Choose an AI provider from the dropdown
- Enter your API key for the selected provider
- Click "Solve Problem" to generate a solution
- View the explanation, code, and hints in the tabbed interface
Generates a solution for a LeetCode problem.
Request Body:
{
"problem_text": "Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.",
"language": "javascript",
"user_level": "intermediate",
"provider": "openai",
"api_key": "your-api-key"
}
Response:
{
"explanation": "To solve this problem, we can use a hash map to store the numbers we've seen so far...",
"code": "function twoSum(nums, target) {\n const map = {};\n for (let i = 0; i < nums.length; i++) {\n const complement = target - nums[i];\n if (map[complement] !== undefined) {\n return [map[complement], i];\n }\n map[nums[i]] = i;\n }\n return [];\n}",
"hints": [
"Consider using a hash map to store values you've already seen",
"For each number, check if its complement (target - num) exists in the hash map",
"Time complexity can be reduced to O(n) with the right approach"
],
"timeComplexity": "O(n)",
"spaceComplexity": "O(n)"
}
Returns a list of available AI providers.
Response:
{
"providers": ["openai", "gemini", "claude", "groq"]
}
The application currently supports the following AI providers:
-
OpenAI (GPT-4)
- API Key Format: Starts with "sk-"
- API Documentation: https://platform.openai.com/docs/api-reference
-
Google Gemini
- API Key Format: Any valid API key
- API Documentation: https://ai.google.dev/docs
-
Anthropic Claude
- API Key Format: Starts with "sk-"
- API Documentation: https://docs.anthropic.com/claude/reference/getting-started-with-the-api
-
Groq (Llama 3)
- API Key Format: Starts with "gsk_"
- API Documentation: https://console.groq.com/docs/quickstart
To add a new AI provider:
- Create a new file in the
providers
directory implementing theGenAIProvider
interface - Register the provider in
main.go
- Add the provider to the frontend dropdown in
ProblemInputForm.tsx
Example implementation:
package providers
import (
"context"
"github.com/leetcode-helper/api/models"
)
// NewProviderProvider creates a new provider
func NewProviderProvider() *ProviderProvider {
return &ProviderProvider{
baseURL: "https://api.provider.com/v1/completions",
}
}
// GetName returns the name of the provider
func (p *ProviderProvider) GetName() string {
return "provider"
}
// ValidateAPIKey checks if the API key is valid
func (p *ProviderProvider) ValidateAPIKey(apiKey string) bool {
return len(apiKey) > 0
}
// GenerateSolution generates a solution for a LeetCode problem
func (p *ProviderProvider) GenerateSolution(ctx context.Context, problem string, language string, userLevel string, apiKey string) (*models.SolutionResponse, error) {
// Implementation here
}
- API keys are stored only in the user's browser local storage
- API keys are never stored on the server
- API keys are sent directly from the frontend to the AI provider
- HTTPS should be used in production to secure API key transmission
This project is licensed under the MIT License - see the LICENSE file for details.