Skip to content

A collection of LeetCode solutions and Data Structures & Algorithms (DSA) implementations in python programming language.

Notifications You must be signed in to change notification settings

SHAHSULTANS/LeetCode-DSA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

87 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌟 LeetCode & Data Structures and Algorithms Repository

LeetCode Python SQL Problems Solved Topics Covered

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.

πŸ“‹ Table of Contents

πŸ“– Overview

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

πŸ“ Repository Structure

The repository is organized into folders based on data structures, algorithm techniques, and curated problem sets. Below is the structure with key details:

πŸ” Core Data Structures & Algorithms

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

πŸ” Algorithm Techniques

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

πŸ” Problem Sets

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

πŸ› οΈ Technologies Used

  • 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 and heapq for efficient implementations.
  • Documentation: Markdown for README and notes in specific folders (e.g., .Note.md in DP folder).

πŸš€ How to Use

Prerequisites

  • 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.

Getting Started

  1. Clone the Repository:

    git clone https://github.com/SHAHSULTANS/LeetCode-DSA.git
    cd LeetCode-DSA
  2. Navigate to a Topic:

    cd "1. Recursion"
  3. Run a Python Solution:

    python factorial.py
  4. 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.
  5. 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.
  6. Experiment and Learn:

    • Modify solutions to test alternative approaches.
    • Compare solutions within the same folder to understand different techniques.

Clone Now

πŸ“Š Progress Tracking

  • 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)

Completion Status

  • 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.

Recent Additions

  • 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

πŸ” Problem Sources

  • 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.

πŸ“š Learning Resources

Complement your learning with these resources:

Books

  • πŸ“– "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.

Online Courses

  • πŸŽ“ 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.

Websites

  • 🌐 LeetCode: Problem-solving and discussion forums.
  • 🌐 GeeksForGeeks: Tutorials and practice problems.
  • 🌐 HackerRank: Diverse coding challenges.
  • 🌐 NeetCode: Curated problem lists and solutions.

Videos

  • πŸŽ₯ NeetCode YouTube: Problem walkthroughs and explanations.
  • πŸŽ₯ Tech With Tim: Python-based DSA tutorials.
  • πŸŽ₯ freeCodeCamp: Beginner-to-advanced DSA tutorials.

Communities

  • πŸ’¬ LeetCode Discuss: Community solutions and insights.
  • πŸ’¬ Reddit: r/leetcode and r/learnprogramming for tips and discussions.

πŸ’‘ Coding Best Practices

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.

🀝 Contributing

This is a personal repository, but contributions are welcome to improve solutions or add new ones.

How to Contribute

  1. Fork the repository.
  2. Create a new branch: git checkout -b feature/new-solution.
  3. Add changes with clear comments: git commit -m "Add solution for problem X with complexity analysis".
  4. Push to your branch: git push origin feature/new-solution.
  5. Open a pull request with:
    • Problem number or name.
    • Approach and complexity analysis.
    • Optimizations or alternative solutions.

Guidelines

  • 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).

Contribute Now

πŸ“ License

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.

πŸ“§ Contact

For questions, suggestions, or discussions:


Happy Coding! Keep Learning! 🎯

Consistency is key in mastering DSA. Revisit problems, explore alternative solutions, and practice daily to build confidence and proficiency.

About

A collection of LeetCode solutions and Data Structures & Algorithms (DSA) implementations in python programming language.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages