UNPKG

local-leetcode-trainer

Version:

A complete local LeetCode practice environment with multi-language support - use your IDE, collaborate with AI, submit with confidence

580 lines (453 loc) • 24.1 kB
# šŸŽÆ Local LeetCode Trainer A complete local LeetCode practice environment with **revolutionary AI teaching system** - designed for deep learning and algorithmic mastery, not just solving problems. ## šŸ¤– **NEW: AI Teaching System - Your Personal Coding Tutor** **Experience the future of coding education with intelligent, adaptive guidance that learns with you!** ### ✨ **What Makes This Special:** - 🧠 **Proactive AI Guidance** - Get contextual hints without asking, based on your code patterns - šŸŽÆ **Adaptive Learning** - AI adjusts difficulty and guidance based on your progress and attempts - šŸ’” **Smart Code Analysis** - AI understands your approach and suggests optimizations intelligently - šŸ”„ **Progressive Hints** - From gentle nudges to detailed explanations, escalating as needed - šŸŽ“ **Concept Teaching** - Learn algorithms and patterns, not just solutions - ⚔ **Seamless Integration** - AI teaching is built into every command, no special "AI mode" ### šŸš€ **AI-Enhanced Commands (No Prefixes Needed!)** ```bash # Intelligent hints that adapt to your skill level lct hint two-sum 1 # AI analyzes your approach and provides contextual guidance lct hint valid-parentheses 2 # Progressive hints that build on each other # Deep learning analysis with AI insights lct learn two-sum # Comprehensive algorithm analysis and complexity insights lct learn longest-palindromic-substring # Multiple approach comparisons # AI assistant for any coding question lct ask "when should I use a hash map?" # Get intelligent explanations lct help-me "I don't understand stacks" # Natural language AI assistance ``` ### šŸŽÆ **AI Teaching in Action:** **Traditional Hint System:** ``` šŸ’” Hint: Try using a hash map for O(1) lookups ``` **AI Teaching System:** ``` šŸ¤– **AI-Enhanced Hints for Two Sum** šŸŽÆ **Problem Overview:** This is one of the most fundamental problems in coding interviews! Your goal is to find two numbers that add up to a target sum. šŸ’” **Key Insights:** - Think about the "complement" pattern - What if you could remember numbers you've seen? šŸ’” **Optimization Hint:** I see you're using nested loops - that works but it's O(n²)! Try this approach: 1. Create a Map to store numbers you've seen 2. For each number, check if (target - number) exists 3. This reduces time complexity to O(n)! šŸ’« **Next:** Try `lct hint two-sum 2` for implementation details ``` ## 🧠 **LEARN, Don't Just Solve** **This tool is built for developers who want to truly understand algorithms, not just pass interviews.** ### šŸŽ“ **What You'll Actually Learn:** #### **šŸ” Problem Analysis Skills** - **What is the question really asking?** - Break down complex problem statements into core requirements - **How to catch the key insights** - Identify the critical patterns and constraints that guide solution approach - **Pattern recognition** - Learn to spot common algorithmic patterns across different problems #### **🧩 Algorithm Selection Process** - **Why choose this specific algorithm?** - Understand the reasoning behind algorithm selection - **How to narrow down the solution space** - Systematic approach to eliminate inefficient approaches - **Trade-off analysis** - Learn when to prioritize time vs space complexity #### **šŸ“Š Complexity Analysis** - **Big O intuition** - Develop intuitive understanding of time and space complexity - **Performance optimization** - Learn how to identify and eliminate bottlenecks - **Scalability thinking** - Understand how solutions perform with real-world data sizes #### **šŸŽÆ Problem-Solving Methodology** - **Structured thinking process** - Step-by-step approach to tackle any algorithmic problem - **Edge case identification** - Learn to systematically find and handle corner cases - **Solution validation** - Develop skills to verify correctness and completeness ### šŸ’” **Learning-First Features:** - šŸ¤– **AI Collaboration** - Use ChatGPT, Claude, Copilot to explore different approaches - šŸ” **Deep Debugging** - Add console.logs, breakpoints, step through your logic - šŸ“ **Custom Test Cases** - Create your own scenarios to test understanding - šŸ’­ **Progressive Hints** - Multi-level hint system that guides your thinking process - šŸŽÆ **Algorithmic Insights** - Built-in explanations of why certain approaches work - šŸ“Š **Complexity Analysis** - Understand the performance implications of your solutions ### šŸŽ“ **AI-Powered Learning Methodology:** #### **Step 1: Get AI-Guided Problem Introduction** ```bash lct challenge easy 1 # Get Two Sum problem lct hint two-sum 1 # AI provides problem overview and strategic guidance # AI explains: What is this problem really asking? # AI suggests: What approaches should you consider? ``` #### **Step 2: Explore with AI Code Analysis** ```bash # Start coding your approach lct hint two-sum 2 # AI analyzes your code patterns # AI detects: "I see you're using nested loops..." # AI suggests: "Try using a hash map for O(1) lookups" ``` #### **Step 3: Get Contextual Debugging Help** ```bash # When you encounter errors lct test two-sum # Run tests # AI automatically provides: "Looks like a null pointer issue..." # AI explains: "This happens when you access undefined properties" ``` #### **Step 4: Receive Progressive Guidance** ```bash lct hint two-sum 3 # More specific implementation hints # AI escalates help based on your attempts # AI provides: Step-by-step implementation guidance ``` #### **Step 5: Master the Concept** ```bash lct learn two-sum # Deep algorithmic analysis # AI explains: Time/space complexity trade-offs # AI connects: "This pattern appears in these other problems..." ``` #### **Step 6: Ask Follow-up Questions** ```bash lct ask "why use hash maps instead of arrays?" lct help-me "when should I use two pointers?" # AI provides: Detailed explanations and comparisons # AI suggests: Related concepts and problems to explore ``` ## ✨ Why Practice Locally? **Use Your Development Environment for Deep Learning** Unlike the LeetCode website where you're limited to a basic web editor, the Local LeetCode Trainer gives you a complete learning environment where you can: - 🧠 **Think deeply** - No time pressure, explore multiple approaches - šŸ”¬ **Experiment freely** - Try different algorithms, compare performance - šŸ“š **Build knowledge** - Create your own notes and solution library - šŸ› ļø **Use your tools** - VS Code, IntelliJ, or whatever helps you learn best - ⚔ **Iterate quickly** - No network delays, instant feedback on your ideas - šŸŽÆ **Focus on understanding** - Built-in learning aids and algorithmic guidance ## šŸ†š LeetCode Website vs Local Trainer | Feature | LeetCode Website | Local LeetCode Trainer | |---------|------------------|---------------| | **Development Environment** | 🌐 Web editor only | šŸ› ļø Your IDE + tools | | **AI Collaboration** | āŒ Limited | āœ… Full access | | **Custom Test Cases** | āŒ No | āœ… Yes | | **Debugging Tools** | āŒ Limited | āœ… Full IDE support | | **Code Iteration Speed** | 🐌 Network delays | ⚔ Instant | | **Progress Tracking** | āœ… Yes | āœ… Yes + Local | | **Company Insights** | āœ… Yes | āœ… Yes | | **Official Validation** | āœ… Yes | āŒ No | | **Discussion Forums** | āœ… Yes | āŒ No | ## šŸš€ Quick Start ### Option 1: NPM Installation (Recommended) ```bash # Install globally npm install -g local-leetcode-trainer # Start practicing immediately local-leetcode-trainer challenge easy # or use the short alias lct challenge easy ``` ### Option 2: Clone Repository ```bash # Clone and setup git clone https://github.com/karote00/local-leetcode-trainer cd local-leetcode-trainer yarn install # Use yarn commands yarn challenge easy ``` ### Getting Started ```bash # Choose your language (JavaScript is default) local-leetcode-trainer lang python # Switch to Python lct lang java # Switch to Java lct lang # Show current language # Get your first challenge lct challenge easy # Start coding and testing lct test easy/two-sum lct open easy/two-sum # Opens LeetCode for final submission # Mark as completed when done lct complete easy/two-sum ``` > **šŸ“š Database Scope**: This trainer includes 200+ carefully selected problems covering all essential algorithmic patterns. While LeetCode has 3000+ problems, these 200+ represent the core knowledge needed for technical interviews and software engineering mastery. Quality over quantity! šŸŽÆ ## šŸŽÆ Perfect Workflow ### 1. **Local Development & Learning** ```bash yarn challenge medium # Get a random problem yarn test medium/problem-name # Test your solution locally # Ask AI: "Can you explain this algorithm approach?" # Add console.logs, debug, iterate quickly ``` ### 2. **AI-Powered Learning** - **Explain algorithms**: "How does this hash map approach work?" - **Code review**: "Can you optimize this solution?" - **Debug help**: "Why is my solution failing this test case?" - **Pattern recognition**: "What other problems use this technique?" ### 3. **Final Validation** ```bash yarn open medium/problem-name # Open LeetCode # Copy your working solution and submit yarn complete medium/problem-name # Track your progress ``` ## šŸ“ Smart Organization ``` ā”œā”€ā”€ easy/ │ ā”œā”€ā”€ two-sum/ # Active problems │ ā”œā”€ā”€ palindrome-number/ │ └── completed/ # Finished problems │ ā”œā”€ā”€ valid-parentheses/ │ └── merge-two-lists/ ā”œā”€ā”€ medium/ │ ā”œā”€ā”€ add-two-numbers/ │ └── completed/ ā”œā”€ā”€ hard/ │ └── completed/ └── scripts/ # All the magic happens here ``` ## šŸ› ļø **AI-Enhanced Commands** ### **šŸ¤– AI Teaching & Learning (NEW!)** ```bash # Intelligent hints with contextual AI guidance lct hint two-sum 1 # AI analyzes your approach, provides strategic guidance lct hint valid-parentheses 2 # Progressive hints that build understanding lct hint merge-k-sorted-lists 3 # Advanced guidance for complex problems # Deep learning analysis with AI insights lct learn two-sum # Comprehensive algorithm analysis lct learn longest-palindromic-substring # Multiple approach comparisons lct learn merge-k-sorted-lists # Advanced algorithmic concepts # AI assistant for any coding question lct ask "when should I use a hash map?" # Get intelligent explanations lct help-me "I don't understand stacks" # Natural language assistance lct ask "how to optimize nested loops" # Algorithm optimization guidance ``` ### **šŸŽÆ Core Practice** ```bash lct challenge easy # Get 1 easy problem with AI teaching available lct challenge medium 2 # Get 2 medium problems lct test two-sum # Test your solution locally lct open two-sum # Open LeetCode for final submission ``` ### **šŸŒ Language Management** ```bash lct lang # Show current language & stats lct lang python # Switch to Python (archives current work) lct lang javascript # Switch to JavaScript lct lang java # Switch to Java lct lang cpp # Switch to C++ ``` ### **šŸ“Š Progress Tracking** ```bash lct progress # Check completion progress with AI insights lct complete two-sum # Mark as completed lct complete list # See all completed problems lct complete undo two-sum # Move back to active ``` ### **šŸ¤– AI Teaching Features** - **Contextual Code Analysis**: AI understands your approach and provides relevant hints - **Progressive Learning**: Hints escalate from gentle nudges to detailed explanations - **Smart Error Interpretation**: AI explains runtime errors and debugging strategies - **Concept Teaching**: Focus on understanding algorithms, not just solving problems - **Adaptive Guidance**: AI adjusts help based on your attempts and progress - **Natural Language Assistant**: Ask questions about any coding concept ### **⚔ Smart Features** - **Seamless AI Integration**: AI teaching built into every command, no special modes - **Graceful Fallback**: Traditional hints when AI teaching scripts aren't available - **Auto-detection**: Commands work whether problem is active or completed - **Progress tracking**: See completion stats per difficulty with AI insights - **Company insights**: Know which companies ask each question - **True variety**: 125+ diverse problems with intelligent randomization ## šŸŽØ Features ### šŸŒ Multi-Language Support - **JavaScript** - Default, Node.js execution - **Python** - Python 3 execution - **Java** - Compile and run with JDK - **C++** - Compile with g++ and execute - **Clean switching** - Archives current work when changing languages - **Language-specific templates** - Proper syntax and structure for each language ### šŸŽÆ LeetCode-Accurate Problem Format - **Exact LeetCode formatting** - Problems look identical to the official website - **Complete problem descriptions** - Full descriptions matching LeetCode exactly - **Proper examples** - Input/output/explanation format just like LeetCode - **Real constraints** - Actual constraints from LeetCode problems - **Follow-up questions** - Includes follow-up challenges where applicable - **Perfect function signatures** - JSDoc for JavaScript, type hints for Python - **Automatic definitions** - ListNode definitions for linked list problems - **Solution class format** - Python uses LeetCode's Solution class structure ### šŸ¤– **Revolutionary AI Teaching System (v1.11.0+)** - **Intelligent Tutoring Engine** - YAML-based teaching scripts that adapt to your learning style - **Contextual Code Analysis** - AI understands your approach and provides relevant guidance - **Progressive Hint System** - From gentle nudges to detailed explanations based on attempts - **Smart Error Interpretation** - AI explains runtime errors and suggests debugging strategies - **Concept-First Learning** - Focus on understanding algorithms and patterns, not just solutions - **Natural Language Assistant** - Ask questions about any coding concept in plain English - **Seamless Integration** - AI teaching built into existing commands, no special "AI mode" - **Graceful Fallback** - Traditional hints when AI teaching scripts aren't available ### 🌐 **Comprehensive Problems Database (v1.9.0+)** - **125+ High-Quality Problems** - Carefully curated database with complete problem data - **AI Teaching Scripts** - Growing collection of intelligent tutoring experiences - **True Variety** - Fixed critical bug - no more repeated "Two Sum" problems! - **Perfect Distribution** - Balanced across Easy, Medium, Hard difficulties and all major topics - **Smart Fallback System** - Works seamlessly when LeetCode scraping fails - **Rich Problem Data** - Complete descriptions, examples, constraints, and company tags - **Intelligent Selection** - Advanced randomization with duplicate avoidance - **Offline Reliability** - Full functionality even without internet connection ### šŸŽ“ Completed All Challenges? Congratulations! **šŸŽ‰ You've mastered 200+ carefully selected LeetCode problems - that's incredible!** If you've completed all available challenges in the Local LeetCode Trainer, you've achieved something remarkable. These 200+ problems represent the most important algorithmic patterns and concepts needed for technical interviews and software engineering excellence. #### šŸš€ What's Next? **Option 1: Continue Learning Locally** - **Create Custom Challenges**: You can manually add new problems using the same structure - **Use Learning Tools**: `lct hint`, `lct learn`, and AI integration still work perfectly - **Review and Optimize**: Revisit completed problems to improve your solutions **Option 2: Graduate to LeetCode** - **You're Ready**: With 200+ problems mastered, you have solid algorithmic foundations - **Premium Features**: Explore LeetCode Premium for company-specific problem sets - **Contest Practice**: Participate in weekly contests to test your skills under time pressure - **System Design**: Move to system design problems for senior-level preparation #### šŸ’” Adding Custom Problems You can extend the database by creating new problem files: ```bash # Create a new problem file touch scripts/dynamic/problems/medium/your-problem-name.js # Use the same structure as existing problems # The system will automatically detect and include it ``` #### šŸ† You've Achieved Mastery Completing 200+ algorithmic problems is a significant achievement that puts you in the top tier of software engineers. Whether you continue with more advanced topics or move to real-world applications, you've built a strong foundation for success. **Keep coding, keep learning, and congratulations on your journey! šŸš€** ### šŸ¤– AI-Friendly Environment - **Full IDE integration** - Use your favorite editor with AI assistants - **Debugging support** - Add breakpoints, console.logs, step through code - **Code iteration** - Modify and test instantly without network delays - **Learning conversations** - Ask AI to explain concepts, algorithms, optimizations ### 🧠 Built-in Learning Assistant - **Progressive hints** - Get hints without spoiling the solution - **Algorithm approaches** - Learn multiple ways to solve each problem - **Complexity analysis** - Understand time and space trade-offs - **Pattern recognition** - See connections between similar problems - **Related problems** - Discover what to practice next ### ⚔ Lightning Fast - **Instant testing** - No network delays, immediate feedback - **Zero dependencies** - Tests run with plain Node.js, no Jest/Mocha required - **Local execution** - Everything runs on your machine - **Quick iteration** - Modify code and test in seconds ### šŸ“Š Smart Progress Tracking - **Completion tracking** - Organized by difficulty level - **Progress stats** - See how many problems you've solved - **Review capability** - Test completed problems anytime - **Smart organization** - Clean separation of active vs completed ### šŸ¢ Interview Preparation - **Company insights** - See which companies ask each problem - **Topic categorization** - Practice specific algorithm types - **Difficulty progression** - Start easy, build up to hard problems - **Comprehensive problem database** - 200+ carefully curated problems covering all major patterns ### šŸ“š Database Scope & Expectations **Important**: This trainer contains 200+ high-quality problems, not all 3000+ LeetCode problems. This is intentional: - **Quality over Quantity** - Each problem is carefully selected for maximum learning value - **Core Patterns Coverage** - All essential algorithmic patterns and data structures included - **Interview Readiness** - Problems chosen based on frequency in technical interviews - **Sufficient for Mastery** - 200+ problems provide comprehensive preparation for most engineering roles **After completing all problems**: You'll have mastered the fundamental algorithms needed for software engineering success. You can then graduate to LeetCode Premium for specialized practice or focus on system design and advanced topics. ## šŸ¤– For AI Assistants **This package provides COMPLETE LeetCode practice functionality - no additional implementation needed!** ### āœ… What This Package Already Does - **Problem Generation**: `lct challenge easy` - Creates complete problem files with templates - **Multi-Language Support**: JavaScript, Python, Java, C++ with proper templates - **Testing Framework**: `lct test problem-name` - Runs tests locally with **zero dependencies** - **Progress Tracking**: `lct complete problem-name` - Tracks completed problems - **Learning Assistant**: `lct hint problem-name` - Progressive hints and algorithm analysis - **Browser Integration**: `lct open problem-name` - Opens LeetCode for final submission ### šŸŽÆ When Users Ask for LeetCode Practice Setup **DON'T** create custom implementations. **DO** guide them to use existing commands: ```bash # Instead of building custom problem generators: lct challenge easy # Gets random easy problem lct challenge medium 2 # Gets 2 medium problems # Instead of building custom test runners: lct test easy/two-sum # Tests existing solution # Instead of building progress tracking: lct complete easy/two-sum # Marks as completed lct complete list # Shows all completed problems ``` ### āš ļø Common AI Mistakes to Avoid - **DON'T** build custom problem scrapers - use `lct challenge` - **DON'T** create custom test frameworks - use `lct test` - **DON'T** build progress tracking systems - use `lct complete` - **DON'T** implement hint systems - use `lct hint` and `lct learn` - **DON'T** create language switching logic - use `lct lang` ### šŸ’” How to Help Users Effectively 1. **First**: Check if functionality exists with `lct --help` 2. **Then**: Guide users to appropriate existing commands 3. **Only if needed**: Extend existing functionality, don't replace it ### šŸ“‹ Quick Command Reference for AI ```bash lct challenge easy # Generate problems lct test [problem] # Run tests lct open [problem] # Open in browser lct complete [problem] # Mark complete lct lang [language] # Switch language lct hint [problem] [level] # Get hints lct learn [problem] # Algorithm analysis lct patterns # List patterns ``` ## šŸŽÆ Use Cases ### šŸ›« **Offline Practice** - Airplane flights, train rides, anywhere without internet - Coffee shops with unreliable WiFi - Focus sessions without online distractions ### šŸ¤– **AI-Powered Learning** - Collaborate with AI to understand algorithms - Get code reviews and optimization suggestions - Debug complex solutions with AI assistance - Learn patterns and techniques through conversation ### šŸ”§ **Development Environment** - Use your preferred IDE and extensions - Full debugging capabilities - Custom test cases and edge case exploration - Integration with your development workflow ### šŸ“ˆ **Skill Building** - Systematic practice with progress tracking - Focus on specific topics or difficulty levels - Build confidence before official submissions - Create a personal library of solved problems ## 🚦 Getting Started ### Prerequisites - Node.js (v14 or higher) - Yarn or npm - Your favorite code editor ### Installation ```bash git clone https://github.com/username/local-leetcode-trainer cd local-leetcode-trainer yarn install ``` ### **Your First AI-Guided Problem** ```bash # Get a challenge with AI teaching lct challenge easy # Get AI-powered introduction and strategic guidance lct hint two-sum 1 # Start coding with AI watching your approach # The AI will provide contextual hints based on your code patterns # Test your solution lct test two-sum # Get AI analysis of your solution lct learn two-sum # Ask the AI assistant any questions lct ask "why is this O(n) instead of O(n²)?" # When ready, open LeetCode to submit lct open two-sum # Mark as completed with AI celebration lct complete two-sum ``` ## šŸ¤ Contributing We'd love your help making this even better! Here are ways to contribute: - **Add more problems** - Expand the problem database - **Improve test cases** - Add better edge cases and examples - **Enhance scripts** - Make the tools even more powerful - **Documentation** - Help others get started - **Bug reports** - Found an issue? Let us know! ## šŸ“ License MIT License - feel free to use this for your own practice and share with others! ## šŸ™ Acknowledgments - LeetCode for the amazing problem platform - The coding community for inspiration and feedback - AI assistants for making learning more interactive --- **Happy Coding! šŸŽ‰** *Practice anywhere, learn with AI, submit with confidence.*