A comprehensive collection of solutions to LeetCode problems and implementations of various data structures and algorithms. Designed to aid in learning, practicing, and preparing for coding interviews, this repository features solutions in Python and SQL, with detailed comments explaining logic, approach, and time/space complexity to facilitate mastery of DSA concepts.
- Overview
- Repository Structure
- Technologies Used
- How to Use
- Progress Tracking
- Problem Sources
- Learning Resources
- Coding Best Practices
- Contributing
- License
- Contact
This repository is a personal journey to master Data Structures and Algorithms through consistent problem-solving. It includes solutions to over 200 problems from LeetCode, GeeksForGeeks, and other platforms, covering fundamental and advanced topics. The code is organized by topic and difficulty, emphasizing clarity, efficiency, and readability. Each solution includes:
- Problem-solving approach with detailed comments.
- Time and space complexity analysis (e.g., O(n), O(log n)).
- Alternative strategies for deeper understanding.
This resource is ideal for aspiring developers, competitive programmers, and anyone preparing for technical interviews.
Explore the Repository | View on GitHub
The repository is organized into folders based on data structures, algorithm techniques, and curated problem sets. Below is the structure with key details:
Folder | Description | Key Files |
---|---|---|
Recursion | Recursive techniques for problems like factorial, Fibonacci, and string manipulation | factorial.py , fibonacci_number.py , decode_string.py , x_pow_n.py |
Array | Array operations, including 1D/2D arrays and real-world applications | array_create.py , two_dimension_ar.py , project_avg_weather.py |
List | List-based problems, including two-sum and missing element detection | two_sum.py , Find_missing_element.py , list_operation.py |
Dictionary | Dictionary operations for efficient key-value pair handling | dictionary_operation.py , delete_from_dictionary.py , dictionary_method.py |
Tuple | Tuple operations and hash-based problems | intialize_touple.py , hash_function.py |
Singly Linked List | Singly linked list operations and LeetCode problems | singly_linked_list_creation.py , 143_reorder_the_list.py , operation_on_link_list.py |
Circular Singly Linked List | Circular linked list implementations | initialize_circular_linked_list.py , insertion_in_circular_link_list.py , delete_from_circular_linked_list.py |
Stack | Stack implementations and size operations | stack_using_list.py , size_stk.py |
Queue | Queue implementations, including deque and two-stack approaches | queue_implementation_using_two_stack.py , animal_shelter.py , build_in_deque.py |
Tree | Binary tree problems, including path finding and serialization | 297_serialize_deserialize_tree.py , 257_tree_paths.py , 572_subtree_another_tree.py |
Binary Search Tree | Binary Search Tree (BST) implementations | BST_implement.py |
Heap Tree | Heap operations like insertion and extraction | insert_into_heap.py , exact_from_heap.py |
Graph | Graph algorithms, including cycle detection and grid-based problems | 994_Rotting_oranges.py , cycle_detection_GKS.py |
Trie | Trie data structure implementation | trie_implementation.py |
Folder | Description | Key Files |
---|---|---|
Greedy Algorithm | Greedy solutions for problems like knapsack and interval scheduling | fractional_kanpsack.py , 435_non_overlapping_intervals.py |
DP + Divide and Conquer | Dynamic programming and divide-and-conquer solutions | 0_1_knapsack.py , 647_palindromic_substring.py , 213_House_RobberII.py , Edit_distance.py |
Backtracking | Backtracking problems like combinations and word search | 39_combination_sum.py , 79_Word_Search.py , 78_subsets.py |
Sliding Window | Sliding window technique for string and array problems | 424_longest_repeating_character_replacement.py |
Number Theory | Number theory problems like GCD and prime factorization | 1071_greatest_common_divisor_of_strings.py , 1492_the_kth_factor_of_n.py , kth_prime_spoz.py |
Folder | Description | Key Files |
---|---|---|
Top 150 Interview | LeetCode's top 150 interview questions covering a wide range of topics | 1_two_sum.py , 206_reverse_link_list.py , 300_LIS.py , 3_longest_substring_without_repeat.py |
Top 50 SQL | SQL-based LeetCode problems for database queries | 1068_product_sales_analysisI.sql , 1378_Replace_Employee_ID.sql , 577_Employee_Bonus.sql |
- Python 3: Primary language for algorithm and data structure implementations.
- SQL: For database-related LeetCode problems.
- Data Structures: Arrays, Linked Lists (Singly and Circular), Stacks, Queues, Trees, Binary Search Trees, Heaps, Tries, Graphs.
- Algorithms: Recursion, Dynamic Programming, Backtracking, Greedy, Divide and Conquer, Sliding Window, Number Theory.
- Tools:
- Git: Version control for tracking changes and collaboration.
- Visual Studio Code: Primary IDE for development and debugging.
- Python Libraries: Built-in libraries like
collections
andheapq
for efficient implementations.
- Documentation: Markdown for README and notes in specific folders (e.g.,
.Note.md
in DP folder).
- Python 3.6+: Install via
pip install python
if not already installed. - SQL Environment: Use MySQL, PostgreSQL, or similar for SQL problems.
- Git: For cloning the repository.
-
Clone the Repository:
git clone https://github.com/SHAHSULTANS/LeetCode-DSA.git cd LeetCode-DSA
-
Navigate to a Topic:
cd "1. Recursion"
-
Run a Python Solution:
python factorial.py
-
Execute SQL Solutions:
- Copy the SQL query from a file (e.g.,
1068_product_sales_analysisI.sql
). - Run it in a database environment like MySQL Workbench or pgAdmin.
- Copy the SQL query from a file (e.g.,
-
Explore Solutions:
- Each file includes comments with:
- Problem description.
- Approach and logic.
- Time and space complexity (e.g., O(n), O(log n)).
- Alternative approaches where applicable.
- Files are named with LeetCode problem numbers or descriptive titles for easy reference.
- Each file includes comments with:
-
Experiment and Learn:
- Modify solutions to test alternative approaches.
- Compare solutions within the same folder to understand different techniques.
- Total Problems Solved: 200+ (150+ LeetCode problems + additional DSA implementations)
- Topics Covered: 20+ DSA concepts, from basic arrays to advanced graph algorithms.
- Difficulty Distribution:
- π’ Easy: ~35% (70+ problems)
- π‘ Medium: ~50% (100+ problems)
- π΄ Hard: ~15% (30+ problems)
- LeetCode Top 150: π©π©π©π©π©π©π©π©π©β¬ (90% complete, 135/150 problems solved)
- Top 50 SQL: π©β¬β¬β¬β¬β¬β¬β¬β¬β¬ (10% complete, 5/50 problems solved)
- Other Topics: Ongoing, with regular additions to DP, Backtracking, and Graphs.
- Dynamic Programming:
647_palindromic_substring.py
,213_House_RobberII.py
- Backtracking:
39_combination_sum.py
,79_Word_Search.py
- Graphs:
994_Rotting_oranges.py
- SQL:
1068_product_sales_analysisI.sql
- LeetCode: Primary source for algorithmic and SQL problems, focusing on Top 150 Interview Questions and Top 50 SQL.
- GeeksForGeeks: Foundational DSA concepts and problems (e.g.,
cycle_detection_GKS.py
,kth_prime_spoz.py
). - Other Platforms: Problems inspired by HackerRank, Codeforces, and custom implementations.
Complement your learning with these resources:
- π "Introduction to Algorithms" by Cormen et al. (CLRS): Comprehensive DSA reference.
- π "Cracking the Coding Interview" by Gayle Laakmann McDowell: Interview-focused problems.
- π "Algorithms" by Robert Sedgewick and Kevin Wayne: Practical algorithm implementations.
- π LeetCode's Explore Section: Structured learning paths.
- π Coursera's Algorithms Specialization by Stanford: In-depth algorithm courses.
- π Udemy's Master the Coding Interview: DSA-focused training.
- π LeetCode: Problem-solving and discussion forums.
- π GeeksForGeeks: Tutorials and practice problems.
- π HackerRank: Diverse coding challenges.
- π NeetCode: Curated problem lists and solutions.
- π₯ NeetCode YouTube: Problem walkthroughs and explanations.
- π₯ Tech With Tim: Python-based DSA tutorials.
- π₯ freeCodeCamp: Beginner-to-advanced DSA tutorials.
- π¬ LeetCode Discuss: Community solutions and insights.
- π¬ Reddit: r/leetcode and r/learnprogramming for tips and discussions.
To ensure high-quality solutions:
- Code Readability: Clear variable names, consistent formatting, and PEP 8 compliance.
- Documentation: Each solution includes:
- Problem statement or link.
- Approach explanation (e.g., iterative vs. recursive).
- Time/space complexity (e.g., O(n log n) time, O(1) space).
- Edge case notes and optimizations.
- Modularity: Use functions and classes for reusable, maintainable code.
- Testing: Solutions tested against provided and edge cases.
- Optimization: Includes brute-force and optimized approaches for learning.
This is a personal repository, but contributions are welcome to improve solutions or add new ones.
- Fork the repository.
- Create a new branch:
git checkout -b feature/new-solution
. - Add changes with clear comments:
git commit -m "Add solution for problem X with complexity analysis"
. - Push to your branch:
git push origin feature/new-solution
. - Open a pull request with:
- Problem number or name.
- Approach and complexity analysis.
- Optimizations or alternative solutions.
- Follow PEP 8 standards for Python code.
- Include detailed comments explaining logic and complexity.
- Test solutions with multiple test cases, including edge cases.
- Use descriptive file names (e.g.,
problem_number_title.py
for LeetCode problems).
This project is licensed under the MIT License. Use the code for educational purposes, personal practice, or as a reference. See the LICENSE file for details.
For questions, suggestions, or discussions:
- GitHub Issues: Open an issue for specific problems or suggestions.
- Email: [email protected]
- LinkedIn: Your LinkedIn Profile
- LeetCode Profile: Your LeetCode Profile
Happy Coding! Keep Learning! π―
Consistency is key in mastering DSA. Revisit problems, explore alternative solutions, and practice daily to build confidence and proficiency.