{"id":22894801,"url":"https://github.com/mathusanm6/leetcode","last_synced_at":"2025-08-28T16:52:07.197Z","repository":{"id":113828119,"uuid":"534686172","full_name":"mathusanm6/LeetCode","owner":"mathusanm6","description":"Solutions for Leetcode Problems (tested using pytest and continuous integration)","archived":false,"fork":false,"pushed_at":"2024-11-01T09:33:14.000Z","size":150,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T01:34:52.708Z","etag":null,"topics":["algorithms","algorithms-and-data-structures","continuous-integration","data-structures","flake8","leetcode-python","leetcode-solutions","pytest"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathusanm6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-09T14:53:29.000Z","updated_at":"2024-11-01T09:33:10.000Z","dependencies_parsed_at":"2025-02-07T01:31:35.137Z","dependency_job_id":"e4792e95-22e9-44c3-b4d5-fb6a36f24aea","html_url":"https://github.com/mathusanm6/LeetCode","commit_stats":null,"previous_names":["mathusanm6/leetcode"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathusanm6%2FLeetCode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathusanm6%2FLeetCode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathusanm6%2FLeetCode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathusanm6%2FLeetCode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathusanm6","download_url":"https://codeload.github.com/mathusanm6/LeetCode/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246552966,"owners_count":20795835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","algorithms-and-data-structures","continuous-integration","data-structures","flake8","leetcode-python","leetcode-solutions","pytest"],"created_at":"2024-12-13T23:19:51.722Z","updated_at":"2025-03-31T22:40:18.710Z","avatar_url":"https://github.com/mathusanm6.png","language":"Python","readme":"# Leetcode\n\n[![Cpp Format \u0026 Test](https://github.com/mathusanm6/LeetCode/actions/workflows/cpp-package.yml/badge.svg)](https://github.com/mathusanm6/LeetCode/actions/workflows/cpp-package.yml)\n[![Python CI (conda)](https://github.com/mathusanMe/LeetCode/actions/workflows/python-package-conda.yml/badge.svg)](https://github.com/mathusanMe/LeetCode/actions/workflows/python-package-conda.yml)\n\n## Description\n\nThis repository contains my solutions to LeetCode problems. I will be updating this repository with my solutions as I solve more problems. I have included a test suite for each solution.\n\n## Running Tests\n\n### Python Tests\n\nTo run the Python test suite, use the following command in **the repository directory**:\n\n```bash\npytest python\n```\n\n### C++ Tests\n\nTo build and run the C++ test suite, use the following commands in the repository directory:\n\n```bash\ncd cpp\nmake all\nmake run_tests\n```\n\n## Algorithms\n\n- [Arrays \u0026 Hashing](#arrays--hashing)\n- [Two Pointers](#two-pointers)\n- [Sliding Window](#sliding-window)\n- [Stack](#stack)\n- [Matrix](#matrix)\n- [Intervals](#intervals)\n- [Linked List](#linked-list)\n- [Binary Tree General](#binary-tree-general)\n- [Binary Search Tree](#binary-search-tree)\n- [Graph General](#graph-general)\n\n## Arrays \u0026 Hashing\n\n| #   | Title                                                                                       | Solution                                                                                    | Time           | Space      | Difficulty | Tag | Note                                                                               |\n| --- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | -------------- | ---------- | ---------- | --- | ---------------------------------------------------------------------------------- |\n| 1   | [Two Sum](https://leetcode.com/problems/two-sum/)                                           | [Python](./python/problems/easy/two_sum.py), [C++](./cpp/problems/easy/two_sum/two_sum.cpp) | _O(n)_         | _O(n)_     | Easy       |     |                                                                                    |\n| 49  | [Group Anagrams](https://leetcode.com/problems/group-anagrams/)                             | [Python](./python/problems/medium/group_anagrams.py)                                        | _O(NK)_        | _O(NK)_    | Medium     |     | _N_ is the number of strings and _K_ is the maximum length of a single string      |\n| 88  | [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/)                     | [Python](./python/problems/easy/merge_sorted_array.py)                                      | _O(n + m)_     | _O(1)_     | Easy       |     | Two-Pointers, Reverse                                                              |\n| 128 | [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) | [Python](./python/problems/medium/longest_consecutive_sequence.py)                          | _O(n)_         | _O(n)_     | Medium     |     | Tricky solution!                                                                   |\n| 135 | [Candy](https://leetcode.com/problems/candy/)                                               | [Python](./python/problems/hard/candy.py)                                                   | _O(n)_         | _O(n)_     | Hard       |     | Enjoyed solving it!                                                                |\n| 217 | [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/)                     | [Python](./python/problems/easy/contains_duplicate.py)                                      | _O(n)_         | _O(n)_     | Easy       |     |                                                                                    |\n| 238 | [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) | [Python](./python/problems/medium/product_of_array_except_self.py)                          | _O(n)_         | _O(1)_     | Medium     |     | Interesting solution!                                                              |\n| 242 | [Valid Anagram](https://leetcode.com/problems/valid-anagram/)                               | [Python](./python/problems/easy/valid_anagram.py)                                           | _O(n)_         | _O(n)_     | Easy       |     | Given Unicode characters support for Python3, the follow-up question is irrelevant |\n| 271 | [Encode and Decode Strings](https://leetcode.com/problems/encode-and-decode-strings/)       | [Python](./python/problems/medium/encode_and_decode_strings.py)                             | _O(n)_         | _O(n)_     | Medium     |     |\n| 347 | [Top K Frequent Elements](https://leetcode.com/problems/top-k-frequent-elements/)           | [Python](./python/problems/medium/top_k_frequent_elements.py)                               | _O(N\\*log(K))_ | _O(N + K)_ | Medium     |     | Requires MinHeap                                                                   |\n| 383 | [Ransom Note](https://leetcode.com/problems/ransom-note/)                                   | [Python](./python/problems/easy/ransom_note.py)                                             | _O(n)_         | _O(1)_     | Easy       |     | Fixed List                                                                         |\n\n## Two-Pointers\n\n| #   | Title                                                                                                 | Solution                                                                                                                               | Time     | Space            | Difficulty | Tag | Note                                                                                      |\n| --- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | -------- | ---------------- | ---------- | --- | ----------------------------------------------------------------------------------------- |\n| 11  | [Container With Most Water](https://leetcode.com/problems/container-with-most-water/)                 | [Python](./python/problems/medium/container_with_most_water.py)                                                                        | _O(n)_   | _O(1)_           | Medium     |     |                                                                                           |\n| 15  | [3Sum](https://leetcode.com/problems/3sum/)                                                           | [Python](./python/problems/medium/three_sum.py)                                                                                        | _O(n^2)_ | _O(1)_           | Medium     |     |                                                                                           |\n| 42  | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/)                             | [Python _O(n)_](./python/problems/hard/trapping_rain_water_o_n.py), [Python _O(1)_](./python/problems/hard/trapping_rain_water_o_1.py) | _O(n)_   | _O(n)_ or _O(1)_ | Hard       |     | Initially proposed an O(n) space complexity solution, but discovered an O(1) alternative. |\n| 125 | [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/)                                   | [Python](./python/problems/easy/valid_palindrome.py)                                                                                   | _O(n)_   | _O(1)_           | Easy       |     |                                                                                           |\n| 167 | [Two Sum II - Input Array is Sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/) | [Python](./python/problems/medium/two_sum_ii_input_array_is_sorted.py)                                                                 | _O(n)_   | _O(1)_           | Medium     |     |                                                                                           |\n\n## Sliding-Window\n\n| #   | Title                                                                                                                           | Solution                                                                             | Time                                                      | Space                                                                               | Difficulty | Tag | Note                                                                         |\n| --- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------- | ----------------------------------------------------------------------------------- | ---------- | --- | ---------------------------------------------------------------------------- |\n| 3   | [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) | [Python](./python/problems/medium/longest_substring_without_repeating_characters.py) | _O(n)_                                                    | _O(min(n, m))_, _n_ being size of the string and _m_ being the size of the alphabet | Medium     |     | A better solution would be to jump to the point where we have a valid string |\n| 76  | [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/)                                             | [Python](./python/problems/hard/minimum_window_substring.py)                         | _O(m + n)_, _m_ being size of `s` and _n_ the size of `t` | _O(l)_, _l_ being the number of unique characters in `t`                            | Hard       |     |                                                                              |\n| 121 | [Best Time to But and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/)                               | [Python](./python/problems/easy/best_time_to_buy_and_sell_stock.py)                  | _O(n)_                                                    | _O(1)_                                                                              | Easy       |     |                                                                              |\n| 209 | [Minimum Size Subarray Sum](https://leetcode.com/problems/minimum-size-subarray-sum/)                                           | [Python](./python/problems/medium/minimum_size_subarray_sum.py)                      | _O(n)_                                                    | _O(1)_                                                                              | Medium     |     |                                                                              |\n| 239 | [Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)                                                 | [Python](./python/problems/hard/sliding_window_maximum.py)                           | _O(n)_, _n_ being the length of `nums`                    | _O(k)_, _k_ being the window size                                                   | Hard       |     |                                                                              |\n| 424 | [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/)               | [Python](./python/problems/medium/longest_repeating_character_replacement.py)        | _O(n)_                                                    | _O(1)_                                                                              | Medium     |     |                                                                              |\n| 567 | [Permutation in String](https://leetcode.com/problems/permutation-in-string/)                                                   | [Python](./python/problems/medium/permutation_in_string.py)                          | _O(n)_, _n_ being the length of s2                        | _O(k)_, _k_ being the length of s1                                                  | Medium     |     |                                                                              |\n\n## Stack\n\n| #   | Title                                                                                               | Solution                                                               | Time             | Space  | Difficulty | Tag | Note                            |\n| --- | --------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ---------------- | ------ | ---------- | --- | ------------------------------- |\n| 20  | [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/)                               | [Python](./python/problems/easy/valid_parentheses.py)                  | _O(n)_           | _O(n)_ | Easy       |     |                                 |\n| 22  | [Generate Parentheses](https://leetcode.com/problems/generate-parentheses/)                         | [Python](./python/problems/medium/generate_parentheses.py)             | _O(4^n/sqrt(n))_ | _O(n)_ | Medium     |     |                                 |\n| 150 | [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) | [Python](./python/problems/medium/evaluate_reverse_polish_notation.py) | _O(n)_           | _O(n)_ | Medium     |     |                                 |\n| 155 | [Min Stack](https://leetcode.com/problems/min-stack/)                                               | [Python](./python/problems/medium/min_stack.py)                        | _O(1)_           | _O(1)_ | Medium     |     | Tuple in stack is interesting ! |\n\n## Matrix\n\n| #   | Title                                                       | Solution                                           | Time   | Space  | Difficulty | Tag | Note |\n| --- | ----------------------------------------------------------- | -------------------------------------------------- | ------ | ------ | ---------- | --- | ---- |\n| 36  | [Valid Sudoku](https://leetcode.com/problems/valid-sudoku/) | [Python](./python/problems/medium/valid_sudoku.py) | _O(1)_ | _O(1)_ | Medium     |     |      |\n\n## Intervals\n\n| #   | Title                                                           | Solution                                           | Time   | Space  | Difficulty | Tag | Note |\n| --- | --------------------------------------------------------------- | -------------------------------------------------- | ------ | ------ | ---------- | --- | ---- |\n| 228 | [Summary Ranges](https://leetcode.com/problems/summary-ranges/) | [Python](./python/problems/easy/summary_ranges.py) | _O(n)_ | _O(n)_ | Easy       |     |      |\n\n## Linked-List\n\n| #   | Title                                                                 | Solution                                              | Time   | Space  | Difficulty | Tag | Note |\n| --- | --------------------------------------------------------------------- | ----------------------------------------------------- | ------ | ------ | ---------- | --- | ---- |\n| 141 | [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/) | [Python](./python/problems/easy/linked_list_cycle.py) | _O(n)_ | _O(1)_ | Easy       |     |      |\n\n## Binary-Tree-General\n\n| #   | Title                                                                                       | Solution                                                          | Time   | Space  | Difficulty | Tag | Note             |\n| --- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------ | ------ | ---------- | --- | ---------------- |\n| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [Python](./python/problems/easy//maximum_depth_of_binary_tree.py) | _O(n)_ | _O(1)_ | Easy       | DFS | Use FIFO for BFS |\n\n## Binary-Tree-BFS\n\n| #   | Title                                                                                     | Solution                                                          | Time   | Space                                                  | Difficulty | Tag | Note |\n| --- | ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------ | ------------------------------------------------------ | ---------- | --- | ---- |\n| 199 | [Binary Tree Right Side View](https://leetcode.com/problems/binary-tree-right-side-view/) | [Python](./python/problems/medium/binary_tree_right_side_view.py) | _O(n)_ | _O(w)_ where w is the maximum width of the binary tree | Medium     |     |      |\n\n## Binary-Search-Tree\n\n| #   | Title                                                                                                   | Solution                                                               | Time   | Space  | Difficulty | Tag | Note               |\n| --- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- | ------ | ------ | ---------- | --- | ------------------ |\n| 530 | [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst/) | [Python](./python/problems/easy/minimum_absolute_difference_in_bst.py) | _O(n)_ | _O(1)_ | Easy       |     | In-order traversal |\n\n## Graph-General\n\n| #   | Title                                                                 | Solution                                                | Time        | Space  | Difficulty | Tag | Note |\n| --- | --------------------------------------------------------------------- | ------------------------------------------------------- | ----------- | ------ | ---------- | --- | ---- |\n| 200 | [Number of Islands](https://leetcode.com/problems/number-of-islands/) | [Python](./python/problems/medium/number_of_islands.py) | _O(n \\* m)_ | _O(1)_ | Medium     |     |      |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathusanm6%2Fleetcode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathusanm6%2Fleetcode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathusanm6%2Fleetcode/lists"}