Skip to content

Solving Data Structure and Algorithm Problems on LeetCode in C++

License

Notifications You must be signed in to change notification settings

abdulaziz7225/leetcode-problems-in-cpp

Repository files navigation

Solving Data Structure and Algorithm Problems on LeetCode Using C++

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.

🗂️ Repository Structure

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

Directory Layout


📂 .
├── 📁 backtracking
│   ├── 📁 medium
│   │   ├── 22.generate_parentheses.cpp
│   │   ├── 46.permutations.cpp
│   │   ├── 47.permutations_ii.cpp
│   │   ├── 78.subsets.cpp
│   │   ├── 784.letter_case_permutation.cpp
│   │   ├── 90.subsets_ii.cpp
│   │   └── 95.unique_binary_search_trees_ii.cpp
├── 📁 binary-search
│   ├── 📁 easy
│   │   ├── 35.search_insert_position.cpp
│   │   └── 744.find_smallest_letter_greater_than_target.cpp
│   ├── 📁 hard
│   │   └── 154.find_minimum_in_rotated_sorted_array_ii.cpp
│   ├── 📁 medium
│   │   ├── 153.find_minimum_in_rotated_sorted_array.cpp
│   │   ├── 33.search_in_rotated_sorted_array.cpp
│   │   ├── 34.find_first_and_last_position_of_element_in_sorted_array.cpp
│   │   ├── 702.search_in_a_sorted_array_of_unknown_size.cpp
│   │   └── 81.search_in_rotated_sorted_array_ii.cpp
├── 📁 bit-manipulation
│   ├── 📁 easy
│   │   ├── 1009.complement_of_base_10_integer.cpp
│   │   ├── 136.single_number.cpp
│   │   ├── 476.number_complement.cpp
│   │   └── 832.flipping_an_image.cpp
│   ├── 📁 medium
│   │   ├── 137.single_number_ii.cpp
│   │   └── 260.single_number_iii.cpp
├── 📁 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
│   │   └── 2502.design_memory_allocator.cpp
├── 📁 dynamic-programming
│   ├── 📁 easy
│   │   └── 509.fibonacci_number.cpp
│   ├── 📁 medium
│   │   ├── 241.different_ways_to_add_parentheses.cpp
│   │   └── 96.unique_binary_search_trees.cpp
├── 📁 graph
│   ├── 📁 easy
│   │   └── 1971.find_if_path_exists_in_graph.cpp
│   ├── 📁 hard
│   │   └── 815.bus_routes.cpp
│   ├── 📁 medium
│   │   ├── 1557.minimum_number_of_vertices_to_reach_all_nodes.cpp
│   │   ├── 547.number_of_provinces.cpp
│   │   └── 802.find_eventual_safe_states.cpp
├── 📁 heap-priority-queue
│   ├── 📁 easy
│   │   └── 703.kth_largest_element_in_a_stream.cpp
│   ├── 📁 hard
│   │   └── 295.find_median_from_data_stream.cpp
│   ├── 📁 medium
│   │   ├── 1167.minimum_cost_to_connect_sticks.cpp
│   │   ├── 215.kth_largest_element_in_an_array.cpp
│   │   ├── 347.top_k_frequent_elements.cpp
│   │   ├── 436.find_right_interval.cpp
│   │   ├── 451.sort_characters_by_frequency.cpp
│   │   └── 973.k_closest_points_to_origin.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!


🔑 Problem Categories

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

🛠️ Solution Format

Each solution file contains:

  1. Problem Description: A detailed explanation of the problem, its constraints, and examples.
  2. Test Cases: Example inputs and expected outputs.
  3. C++ Implementation: The function or class implementing the solution.
  4. Time and Space Complexity Analysis: A brief analysis of the efficiency of the solution.

About

Solving Data Structure and Algorithm Problems on LeetCode in C++

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published