This repository contains 🌟 solutions to various data structure and algorithm problems from LeetCode. All solutions are implemented in C++ and are structured for easy understanding and reusability.
- 📂 Each solution is stored in a separate C++ file, named according to the problem number and title.
- 🏷️ Organized by category: Arrays, Strings, Trees, Graphs, and more.
📂 .
├── 📁 depth-first-search
│ ├── 📁 easy
│ │ ├── 112.path_sum.cpp
│ │ ├── 257.binary_tree_paths.cpp
│ │ └── 543.diameter_of_binary_tree.cpp
│ ├── 📁 hard
│ │ └── 124.binary_tree_maximum_path_sum.cpp
│ ├── 📁 medium
│ │ ├── 113.path_sum_ii.cpp
│ │ ├── 129.sum_root_to_leaf_numbers.cpp
│ │ ├── 1430.check_if_a_string_is_a_valid_sequence_from_root_to_leaves_path.cpp
│ │ └── 437.path_sum_iii.cpp
├── 📁 design
│ ├── 📁 easy
│ │ ├── 225.implement_stack_using_queues.cpp
│ │ └── 232.implement_queue_using_stacks.cpp
│ ├── 📁 medium
│ │ └── 146.lru_cache.cpp
├── 📁 dynamic-programming
│ ├── 📁 easy
│ │ └── 509.fibonacci_number.cpp
├── 📁 heap-priority-queue
│ ├── 📁 hard
│ │ └── 295.find_median_from_data_stream.cpp
├── 📁 linked-list
│ ├── 📁 easy
│ │ ├── 206.reverse_linked_list.cpp
│ │ ├── 21.merge_two_sorted_lists.cpp
│ │ └── 83.remove_duplicates_from_sorted_list.cpp
│ ├── 📁 medium
│ │ ├── 24.swap_nodes_in_pairs.cpp
│ │ ├── 82.remove_duplicates_from_sorted_list_ii.cpp
│ │ └── 92.reverse_linked_list_ii.cpp
├── 📁 matrix
│ ├── 📁 easy
│ │ ├── 463.island_perimeter.cpp
│ │ └── 733.flood_fill.cpp
│ ├── 📁 medium
│ │ ├── 1254.number_of_closed_islands.cpp
│ │ ├── 1559.detect_cycles_in_2d_grid.cpp
│ │ ├── 200.number_of_islands.cpp
│ │ ├── 694.number_of_distinct_islands.cpp
│ │ └── 695.max_area_of_island.cpp
├── 📁 prefix-sum
│ ├── 📁 easy
│ │ └── 303.range_sum_query_immutable.cpp
├── 📁 stack
│ ├── 📁 medium
│ │ └── 155.min_stack.cpp
├── LICENSE
├── README.md
├── directory_layout_script.py
├── problem_description_script.py
└── requirements.txt
💡 Pro Tip: Click the filenames to view each solution directly on GitHub!
| 📂 Category | 📜 Description |
|---|---|
| 📊 Arrays | Searching, sorting, subarray sums, and more. |
| 🧵 Strings | String manipulations, substrings, and pattern matching. |
| 🔗 Linked Lists | Singly, doubly linked list problems. |
| 🌲 Trees | Binary trees, search trees, and n-ary trees. |
| 🗺️ Graphs | Traversals, shortest paths, and connectivity. |
| 🚀 Dynamic Programming | Optimal substructure and overlapping subproblems. |
Each solution file contains:
- Problem Description: A detailed explanation of the problem, its constraints, and examples.
- Test Cases: Example inputs and expected outputs.
- Python Implementation: The function or class implementing the solution.
- Time and Space Complexity Analysis: A brief analysis of the efficiency of the solution.