{"id":24490428,"url":"https://github.com/alishahusain/newt","last_synced_at":"2025-06-13T14:02:31.514Z","repository":{"id":60383526,"uuid":"535170171","full_name":"alishahusain/newt","owner":"alishahusain","description":"🐸 pattern algorithms data structures in javascript pseudo code space time complexity and most common implementation of each algorithm and data structure 🐸","archived":false,"fork":false,"pushed_at":"2024-10-29T08:20:49.000Z","size":4063,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-29T09:41:21.302Z","etag":null,"topics":["algorithms","dijkstra-algorithm","heap","javascript","tree"],"latest_commit_sha":null,"homepage":"https://github.com/alishahusain/newt","language":"JavaScript","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/alishahusain.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-11T02:26:10.000Z","updated_at":"2024-10-29T08:20:53.000Z","dependencies_parsed_at":"2024-01-22T16:13:25.476Z","dependency_job_id":"44897ae2-9c6b-4b03-9772-3d8d00b3052e","html_url":"https://github.com/alishahusain/newt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alishahusain%2Fnewt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alishahusain%2Fnewt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alishahusain%2Fnewt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alishahusain%2Fnewt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alishahusain","download_url":"https://codeload.github.com/alishahusain/newt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234988195,"owners_count":18918097,"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","dijkstra-algorithm","heap","javascript","tree"],"created_at":"2025-01-21T17:18:09.245Z","updated_at":"2025-06-13T14:02:31.492Z","avatar_url":"https://github.com/alishahusain.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \n\n## 14 Patterns Algorithim\n\u003ctable\u003e\n\u003cth\u003e\u003ch3\u003eUses: Symbol in Pattern\u003c/h3\u003e\u003c/th\u003e\n\u003ctr\u003e\n\u003ctd\u003e\n\u003ch4\u003e📌 = 1 Pointers \u003ch4\u003e \n\u003c/td\u003e\n\u003ctd\u003e\n\u003ch4\u003e📦 = 1 Heap \u003ch4\u003e \n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🚥 = 1 Array \u003ch4\u003e \n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🍽 = 1 Stack\u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🦜 = 1 Queue\u003c/h4\u003e\n\u003c/td\u003e\n\n\n\u003ctd\u003e\n\u003ch4\u003e🗂 = 1 Hash \u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e➕ = 1 Counter \u003c/h4\u003e\n\u003c/td\u003e\n\n\u003c/tr\u003e\n\u003ctr\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🌱 = 1 Node \u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🎡 = 1 Loop \u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e📱 = 1 Graph\u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🔗 = 1 Linked List \u003c/h4\u003e\n\u003c/td\u003e\n\u003ctd\u003e\n\u003ch4\u003e 🪞 = 1 Recursion \u003c/h4\u003e\n\u003c/td\u003e\n\n\u003ctd\u003e\n\u003ch4\u003e🤹‍♀️ = 1 Swap \u003c/h4\u003e\n\u003c/td\u003e\n\u003c/tr\u003e\n\u003c/table\u003e\n\n  \u003cdetails\u003e\n    \u003csummary\u003e  \u003ch1\u003e🪟 Sliding Window : 📌🚥🎡 \u003c/h1\u003e \u003c/summary\u003e\n    \u003cbr\u003e\n  \u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            \u003ch3\u003e❓ SUBSTRING OR SUBARRAY FIND LONGEST OR SMALLEST CONTAIN CHARACTER \u003ch3\u003e\n            \u003ch3\u003e⏰: O(n) 🪐: O(n) \u003c/h3\u003e\n        \u003c/td\u003e\n           \u003ctd colspan=\"2\"\u003e\n               🐣 Maximum Sum Subarray of Size K, Longest Substring with K Distinct CharactersString Anagrams, No-repeat Substring, etc.\n            \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n\u003cpre class=\"notranslate\"\u003e\n\u003ccode\u003e\nfunction findAvgSubArrays(K, arr) {\n  const result = [];\n  let windowSum = 0, windowStart = 0;\n  for (let winEnd = 0; winEnd \u003c arr.length; winEnd++) {\n    windowSum += arr[winEnd];   \n    if (winEnd \u003e= K - 1) {\n      result.push(windowSum / K);             \n      windowSum -= arr[windowStart];\n      windowStart += 1;                     \n    }\n  }\n  return result;\n}\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e\n            \u003cimg\n                src=\"https://miro.medium.com/max/372/0*o-PhzdP_jd_5L2iq.jpg\"\n                alt=\"Sliding Window Pattern\"\n            /\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\n\u003c/table\u003e\n\u003cdetails\u003e\n\u003csummary\u003e🪟 Problems \u003c/summary\u003e\n\u003cbr\u003e\n## [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/) #3 🪟 \n        ❓: Given a string s, find the length of the longest substring without repeating characters.\n        🐣: 1️⃣ Input: s = \"abcabcbb\" Output: 3 Explain: The answer is \"abc\", with the length of 3. 2️⃣ Input: s = \"bbbbb\" Output: 1 Explain: The answer is \"b\", with the length of 1. 3️⃣ Input: s = \"pwwkew\" Output: 3 Explain: The answer is \"wke\", with the length of 3. Notice that the answer must be a substring, \"pwke\" is a subsequence \u0026 not a substring. #4 Input: s = \"\" Output: 0\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n^3) 🪐: O(min(m, n))  \n        🐇 Solution: 🪟 Sliding Window Pattern ⏰: O(n) 🪐: O(n)\n\n            var lengthOfLongestSubstring = function (s) {\n              let result = 0;\n              let left = 0;\n              let right = 0;\n              let set = new Set();\n              while (right \u003c s.length) {\n                if (!set.has(s[right])) {\n                  set.add(s[right]);\n                  right++;\n                  result = Math.max(result, set.size);\n                } else {\n                  set.delete(s[left]);\n                  left++;\n                }\n              }\n              return result;\n            };\n## [Longest Repeating Character Replacement](https://leetcode.com/problems/longest-repeating-character-replacement/) #424 🪟 \n        ❓: You are given a string s \u0026 an integer k. You can choose any character of the string \u0026 change it to any other uppercase English character. You can perform this operation at most k times.\n        Return the length of the longest substring containing the same letter you can get after performing the above operations.\n        🐣: 1️⃣ Input: s = \"ABAB\", k = 2 Output: 4 Explain: Replace the two 'A's with two 'B's or vice versa. 2️⃣ Input: s = \"AABABBA\", k = 1 Output: 4 Explain: Replace the one 'A' in the middle with 'B' \u0026 form \"AABBBBA\". The substring \"BBBB\" has the longest repeating letters, which is 4.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n^2) 🪐: O(1)\n        🐇 Solution: 🪟 Sliding Window Pattern ⏰: O(n) 🪐: O(n)\n\n            var characterReplacement = function (s, k) {\n              let left = 0;\n              let right = 0;\n              let maxCount = 0;\n              let map = new Map();\n              while (right \u003c s.length) {\n                map.set(s[right], (map.get(s[right]) || 0) + 1);\n                maxCount = Math.max(maxCount, map.get(s[right]));\n                if (right - left + 1 - maxCount \u003e k) {\n                  map.set(s[left], map.get(s[left]) - 1);\n                  left++;\n                }\n                right++;\n              }\n              return right - left;\n            };\n## [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) #76 🪟 \n        ❓: Given two strings s \u0026 t of lengths m \u0026 n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string \"\".\n        The testcases will be generated such that the answer is unique.\n        A substring is a contiguous sequence of characters within the string.\n        🐣: 1️⃣ Input: s = \"ADOBECODEBANC\", t = \"ABC\" Output: \"BANC\" Explain: The minimum window substring \"BANC\" includes 'A', 'B', \u0026 'C' from string t. 2️⃣ Input: s = \"a\", t = \"a\" Output: \"a\" 3️⃣ Input: s = \"a\", t = \"aa\" Output: \"\" Explain: Both 'a's from t must be included in the window. Since the largest window of s only has one 'a', return empty string.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n^2) 🪐: O(n)\n        🐇 Solution: 🪟 Sliding Window Pattern ⏰: O(n) 🪐: O(n)\n\n            var minWindow = function (s, t) {\n              let left = 0;\n              let right = 0;\n              let map = new Map();\n              let min = Infinity;\n              let result = \"\";\n              for (let i = 0; i \u003c t.length; i++) {\n                map.set(t[i], (map.get(t[i]) || 0) + 1);\n              }\n              let count = map.size;\n              while (right \u003c s.length) {\n                let char = s[right];\n                if (map.has(char)) {\n                  map.set(char, map.get(char) - 1);\n                  if (map.get(char) === 0) {\n                    count--;\n                  }\n                }\n                right++;\n                while (count === 0) {\n                  if (right - left \u003c min) {\n                    min = right - left;\n                    result = s.substring(left, right);\n                  }\n                  let char = s[left];\n                  if (map.has(char)) {\n                    map.set(char, map.get(char) + 1);\n                    if (map.get(char) \u003e 0) {\n                      count++;\n                    }\n                  }\n                  left++;\n                }\n              }\n              return result;\n            };\n\u003c/details\u003e\n\u003c/details\u003e\n  \u003cdetails\u003e\n    \u003csummary\u003e  \u003ch1\u003e👯 Two Pointers:  📌📌🎡\u003c/h1\u003e \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n           \u003ch3\u003e ❓ FIND A PAIR, TRIPLET or a SUBARRAY \u003ch3\u003e\n            \u003ch3\u003e⏰: O(n) 🪐: O(n)\u003c/h3\u003e\n        \u003c/td\u003e\n            \u003ctd colspan=\"2\"\u003e\n                🐣 Squaring a Sorted Array, Triplets that Sum to Zero, Triplet Sum Close to Target, Triplets with Smaller Sum, Subarrays with Product Less than a Target, Comparing Strings containing Backspaces, etc.\n              \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n\u003cpre class=\"notranslate\"\u003e\n\u003ccode\u003e\nleft = 0;\nright = 0;\nwhile (right \u003c s.length()) {\n    // add s[right] to window\n    right++;\n    while (window needs shrink) {\n        // remove s[left] from window\n        left++;\n    }\n}\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e\n            \u003cimg\n                src=\"https://cdn.emre.me/2019-10-21-two-pointers.png\"\n                alt=\"Two Pointers\"\n            /\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n \u003cdetails\u003e\n    \u003csummary\u003e  \u003ch1\u003e🐰🐢 Fast \u0026 Slow Pointers: 📌📌 🎡\u003c/h1\u003e \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            \u003ch3\u003e ❓ FIND CYCLE IN A LINKED LIST OR FIND THE MIDDLE OF A LINKED LIST \u003c/h3\u003e\n            \u003ch3\u003e⏰:⏰: O(n) 🪐: O(n)\u003c/h3\u003e\n        \u003c/td\u003e\n            \u003ctd colspan=\"2\"\u003e\n                🐣 Linked List Cycle, Palindrome LinkedList, Cycle in a Circular Array, etc.\n              \u003c/td\u003e\n    \u003c/tr\u003e\n        \u003ctr\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n           \u003ch3\u003e🎭 PsuendoCode\u003c/h3\u003e\n\u003cpre class=\"notranslate\"\u003e\n\u003ccode\u003e\nslow = 0;\nfast = 0;\nwhile (fast \u003c s.length()) {\n    if (s[fast] is not a duplicate) {\n        // move slow pointer one step\n        // add s[fast] to window\n        slow++;\n    }\n    // move fast pointer one step\n    fast++;\n}\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e\n            \u003cimg\n                src=\"http://1algo1week.warriorkitty.com/assets/floyds-cycle-finding-algorithm/algorithm.png\"\n                alt=\"Fast \u0026 Slow Pointers Pattern\"\n            /\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003c/details\u003e\n \u003cdetails\u003e\n    \u003csummary\u003e  \u003ch1\u003e🚗🚙 Merge Intervals : 📌📌🚥  \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n            \u003ch3\u003e ❓ MERGE INTERVALS OR FIND OVERLAPPING INTERVALS \u003ch3\u003e\n           \u003ch3\u003e  ⏰: O(nlogn) 🪐: O(n) \u003c/h3\u003e\n        \u003c/td\u003e\n            \u003ctd colspan=\"2\"\u003e\n                🐣 Insert Interval, Intervals Intersection, Conflicting Appointments, Minimum Meeting Rooms, etc.\n              \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n           \u003ch3\u003e🎭 PsuendoCode\u003c/h3\u003e\n\u003cpre class=\"notranslate\"\u003e\n\u003ccode\u003e\nfunction merge(intervals) {\n  if (intervals.length \u003c 2) {\n    return intervals;\n  }\n  // sort the intervals on the start time\n  intervals.sort((a, b) =\u003e a[0] - b[0]);\n  const mergedIntervals = [];\n  let start = intervals[0][0],\n    end = intervals[0][1];\n  for (i = 1; i \u003c intervals.length; i++) {\n    const interval = intervals[i];\n    if (interval[0] \u003c= end) {\n      end = Math.max(interval[1], end);\n    } else {\n      mergedIntervals.push([start, end]);\n      start = interval[0];\n      end = interval[1];\n    }\n  }\n  // add the last interval\n  mergedIntervals.push([start, end]);               \n  return mergedIntervals;\n}\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e\n            \u003cimg\n                src=\"https://cdn.emre.me/2019-10-27-merge-intervals.png\"\n                alt=\"Merge Intervals Pattern\"\n            /\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n      🏁🔚  Mod Binary Search: 📌📌📌🎡 \n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ MINIMUM DIFFERENCE  OR FIND ELEMENT IN INFINITE SORTED ARRAY\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Order-agnostic Binary Search, Ceiling of a Number, Floor of a Number, Next Letter, Number Range, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode 🏁🔚  Mod Binary Search Pattern 🏁🔚\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  start = 0, end = arr.length - 1;\n  while (start \u003c= end) {\n      // calculate the middle of the current range\n      mid = start + (end - star\n      if (key \u003c arr[mid]) {\n          end = mid - 1; // the 'key' can be in the first half\n      } else if (key \u003e arr[mid]) {\n          start = mid + 1; // the 'key' can be in the second half\n      } else { // found the key\n          return mid;\n      }\n  }\n  // element is not found\n  return -1;\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://cdn.emre.me/2019-08-08-binary-search.png\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n \n\u003cdetails\u003e\n\u003csummary\u003e  \u003ch1\u003e\u003calign=\"center\"\u003e 🌀 Cyclic Sort :  🎡🤹‍♀️ \u003c/h1\u003e   \u003c/summary\u003e\n    \u003cbr\u003e\n \u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\n                   \u003ch3\u003e ❓ FIND MISSING # OR  SORT #s IN PLACE  \u003c/h3\u003e\n                              \u003ch3\u003e 🐣 Cyclic Sort, Find the Missing Number, Find all Missing Numbers, \u003cbr/\u003e\n                              Find the Duplicate Number, Find all Duplicate Numbers, Find the Corrupt Pair, etc.\n            \u003c/h3\u003e\n           \u003ch3\u003e ⏰: O(n) 🪐: O(1) \u003c/h3\u003e\n         \u003ch3\u003e🎭 PsuendoCode\u003c/h3\u003e\n\u003cpre class=\"notranslate\"\u003e\n\u003ccode\u003e\n\ni = 0;\nwhile (i \u003c nums.length) {\n    j = nums[i] - 1;\n    if (nums[i] != nums[j])\n        swap(nums, i, j); // put the number in its correct place\n    else\n        i++;\n}\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e\n            \u003cimg\n                src=\"https://cdn.emre.me/2019-10-28-missing-number-example.png\"\n                alt=\"Cyclic Sort Pattern\"\n            /\u003e\n        \u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e  \u003ch1\u003e🔀🔗 Reverse LinkList : 🌱🤹‍♀️🎡 \u003c/h1\u003e   \u003c/summary\u003e\n    \u003cbr\u003e\n \u003ctable\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd\u003e\n          \u003ch3\u003e❓ REVERSE A LINKEDLIST\u003c/h3\u003e\n          \u003ch3\u003e⏰: O(n) 🪐: O(1)\u003c/h3\u003e\n        \u003c/td\u003e\n        \u003ctd\u003e\n           \u003ch3\u003e🐣 Reverse a LinkedList, Reverse a Sub-list, Reverse every K-element Sub-list (medium), etc.\u003c/h3\u003e\n        \u003c/td\u003e\n      \u003c/tr\u003e\n      \u003ctr\u003e\n        \u003ctd\u003e\n          \u003ch3\u003e🎭 PsuendoCode\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  function reverse(head) {\n    let prev = null;\n    while (head !== null) {\n      next = head.next;\n      head.next = prev;\n      prev = head;\n      head = next;\n    }\n    return prev;\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n        \u003c/td\u003e\n         \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://cdn.emre.me/2019-11-04-in-place-reversal.gif\"\u003e \u003c/td\u003e\n      \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n      🌳 BFS : 🦜 🪞\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ FIND MIN DEPTH, MAX DEPTH, LEVEL AVERAGE OF BINARY TREE\u003c/h3\u003e\n       \u003ch3\u003e⏰: O(n) 🪐: O(n)\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Level Order Traversal, Zigzag Traversal, Level Averages in a Binary Tree, \u003cbr/\u003e \n    Minimum Depth of a Binary Tree, Level Order Successor, \u003cbr/\u003e\n    Connect Level Order Siblings, etc. Tree Breadth First Search?\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode 🌳\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  const queue = [root];\n  while (queue.length) {\n      const currentNode = queue.shift();\n      if (currentNode.left) queue.push(currentNode.left);\n      if (currentNode.right) queue.push(currentNode.right);\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://www.guru99.com/images/1/020820_0543_BreadthFirs1.png\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n      🌲 DFS :  🍽🪞\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ FIND PATH WITH MAX SUM OR PATH WITH GIVEN SEQUENCE\u003c/h3\u003e\n       \u003ch3\u003e⏰: O(n) 🪐: O(n)\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Reverse Level Order Traversal, Zigzag Traversal, \u003cbr/\u003e\n    Level Averages in a Binary Tree, Minimum Depth of a Binary Tree, \u003cbr/\u003e\n    Level Order Successor, Connect Level Order Siblings, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode Tree Depth First Search Pattern 🌲\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  Stack\u003c Tree Node stack = new Stack\u003c\u003e();\n  stack.push(root);\n  while (!stack.isEmpty()) {\n      TreeNode currentNode = stack.pop(); \n      if (currentNode.left != null) stack.push(currentNode.left);\n      if (currentNode.right != null) stack.push(currentNode.right);\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://assets.leetcode.com/users/andvary/image_1556551007.png\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n     📦📦 Two Heaps : 📦📦 🎡\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ MEDIAN OF # STREAM FIND K SMALLEST #\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Sliding Window Median, Find the Median of a Number Stream, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode Two Heaps Pattern 📦📦\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  let maxHeap = new MaxHeap();\n  let minHeap = new MinHeap();\n  for (num of nums) {\n      if (maxHeap.isEmpty() || num \u003c= maxHeap.peek()) {\n          maxHeap.push(num);\n      } else {\n          minHeap.push(num);\n      }\n      if (maxHeap.size() \u003e minHeap.size() + 1) {\n          minHeap.push(maxHeap.pop());\n      } else if (maxHeap.size() \u003c minHeap.size()) {\n          maxHeap.push(minHeap.pop());\n      }\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://media.geeksforgeeks.org/wp-content/cdn-uploads/MinHeapAndMaxHeap.png\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n     🐛 Subsets :  🚥🎡\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e \n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ FIND ALL SUBSETS OF A SET OR FIND ALL SUBSETS ADD UP TO GIVEN #PERMUTATIONS AND COMBINATIONS OF SUBSETS\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Find all subsets of a set, Find all subsets of a set with duplicates, Find all subsets with a given sum, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode \u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  let subsets = [[]];\n  for (let i = 0; i \u003c nums.length; i++) {\n      let n = subsets.length;\n      for (let j = 0; j \u003c n; j++) {\n          let set = subsets[j].slice(0);\n          set.push(nums[i]);\n          subsets.push(set);\n      }\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://hackernoon.com/images/G9YRlqC9joZNTWsi1ul7tRkO6tv1-hemg3w8d.jpg\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n     #️⃣ 👑  K TOP :  📦 🎡🎡\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ TOP K #s OR FREQUENCY OF TOP K #s\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Top 'K' Numbers, Kth Largest Number in a Stream, K Closest Points to the Origin, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode K TOP in Javascript:\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  import MinHeap from './DataStructures/Heap/MinHeap.js';\n\n  function findLargestKNum(nums, k) {\n      const minHeap = new MinHeap();\n      for (i = 0; i \u003c k; i++) {\n          minHeap.push(nums[i]);\n      }\n      for (i = k; i \u003c nums.length; i++) {\n          if (nums[i] \u003e minHeap.peek()) {\n              minHeap.pop();\n              minHeap.push(nums[i]);\n          }\n      }\n\n      return minHeap.toArray();\n  }\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://i.ytimg.com/vi/Wh3A29psE_Y/maxresdefault.jpg\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n      #️⃣🚕🚓 K MERGE : 🌱📦🎡🎡\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e❓ MERGE K SORTED ARRAYS OR MERGE K SORTED LISTS\u003c/h3\u003e\n    \u003c/td\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Merge K Sorted Lists, Kth Smallest Number in M Sorted Lists, Kth Smallest Number in a Sorted Matrix, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCodeK MERGE Pattern in Javascript:\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\n  import ListNode from \"DataStructures/LinkedList/ListNode.js\";\n  import MinHeap from \"DataStructures/Heaps/MinHeap.js\";\n\n  const mergeKLists = function (lists) {\n    if (lists.length === 0) return null;\n    let dummy = new ListNode();\n    let curr = dummy;\n    let minHeap = new MinHeap();\n    for (let i = 0; i \u003c lists.length; i++) {\n      if (lists[i]) minHeap.insert(lists[i]);\n    }\n    while (minHeap.size() \u003e 0) {\n      let node = minHeap.remove();\n      curr.next = node;\n      curr = curr.next;\n      if (node.next) minHeap.insert(node.next);\n    }\n    return dummy.next;\n  };\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n    \u003ctd colspan=\"3\"\u003e \u003cimg src=\"https://i.ytimg.com/vi/Xo54nlPHSpg/maxresdefault.jpg\"\u003e \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e \u003ch1 align=\"center\"\u003e\n     📅 Topological Sort : 📦📱🎡\n    \u003c/h1\u003e  \u003c/summary\u003e\n    \u003cbr\u003e\n\u003ctable\u003e \n  \u003ctr\u003e\n         \u003ctd\u003e\n      \u003ch3\u003e❓ FIND ORDER OF TASKS OR IF GIVEN SEQUENCE IS VALID\u003c/h3\u003e\n    \u003c/td\u003e\n      \u003ctd\u003e\n     \u003cimg src=\"https://slideplayer.com/slide/12886082/78/images/5/Topological+Sort%3A+Definition.jpg\" alt=\"Topological Sort: Definition\" width=\"500\" height=\"500\"\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n    \u003ctr\u003e\n    \u003ctd\u003e\n    \u003ch3\u003e🐣 Tasks Scheduling, Tasks Scheduling Order, All Tasks Scheduling Orders, etc.\u003c/h3\u003e\n    \u003c/td\u003e\n         \u003ctd\u003e\n      \u003ch3\u003e🎭 PsuendoCode  📅  Topological Sort Pattern  📅  in Javascript:\u003c/h3\u003e\n\u003cpre\u003e\n\u003ccode\u003e\nconst Deque = require('collections/deque'); //http://www.collectionsjs\nfunction print_orders(tasks, prerequisites) {\n  sortedOrder = [];\n  if (tasks \u003c= 0) {\n    return false;\n\n  // a. Initialize the graph\n  inDegree = Array(tasks).fill(0); // count of incoming edges\n  graph = Array(tasks).fill(0).map(() =\u003e Array()); // adjacency list g\n  // b. Build the graph\n  prerequisites.forEach((prerequisite) =\u003e {\n    let parent = prerequisite[0],\n      child = prerequisite[1];\n    graph[parent].push(child); // put the child into it's parent's list\n    inDegree[child]++; // increment child's inDegree\n\n  // c. Find all sources i.e., all vertices with 0 in-degrees\n  sources = new Deque();\n  for (i = 0; i \u003c inDegree.length; i++) {\n    if (inDegree[i] === 0) {\n      sources.push(i);\n    }\n\n  print_all_topological_sorts(graph, inDegree, sources, sortedOrder);\n  return sortedOrder;\n\nfunction print_all_topological_sorts(graph, inDegree, sources, sortedOrder) {\n  if (sources.length \u003e 0) {\n    for (i = 0; i \u003c sources.length; i++) {\n      vertex = sources.shift();\n      sortedOrder.push(vertex);\n      sourcesForNextCall = sources.slice(0); // make a copy of sources\n      // only remove the edges, if all of its children are not sources\n      graph[vertex].forEach((child) =\u003e { // get the node's children to decrement their in-degrees\n        inDegree[child]--; // decrement inDegree of child\n        if (inDegree[child] === 0) {\n          sourcesForNextCall.push(child); // save the new source for the next call\n        }\n      });\n      // recursive call to print other orderings from the remaining (and new) sources\n      print_all_topological_sorts(graph, inDegree, sourcesForNextCall, sortedOrder);\n      // backtrack, remove the vertex from the sorted order and put all of its children back to consider\n      // the next source instead of the current vertex\n      sortedOrder\n\u003c/code\u003e\n\u003c/pre\u003e\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\u003c/details\u003e\n\n\n\n      \n\n\n   \n\n\n\n\n\n\n## Other Patterns\n\n## Union Find Algorithm Pattern ♾ -\u003e\n    ❓ # OF CONNECTED COMPONENETS IN UNDIRECTED GRAPH, FIND IF 2 NODES CONNECTED\n    🐣 Number of Connected Components in an Undirected Graph, Find whether two nodes are connected in an undirected graph, etc.\n\n      🎭 PsuendoCode Union Find Algorithm Pattern ♾\n          ⏰: O(V * logV) 🪐: O\n                  function find(int[] parent, i) {\n                      if (parent[i] == -1) return i;\n                      return find(parent, parent[i]);\n            \n                  function union(int[] parent, x, y) {\n                      xset = find(parent, x);\n                      yset = find(parent, y);\n                      parent[xset] = yset;\n                  }\n## Greedy Pattern 💰 -\u003e\n      ❓ MINIMUM # OF MEETINGS MAX OF INTERVALS NOT OVERLAPPING\n      🐣 Activity Selection Problem, Coin Change, Fractional Knapsack Problem, Job Sequencing Problem, Huffman Coding, Prim's Minimum Spanning Tree, Kruskal's Minimum Spanning Tree, Dijkstra's Shortest Path Algorithm, Bellman-Ford Algorithm, Floyd-Warshall Algorithm, Travelling Salesman Problem\n\n      🎭 PsuendoCode Greedy Pattern 💰\n        ⏰: O(nlogn) 🪐: O(1)\n  \n              Arrays.sort(intervals, (a, b) -\u003e Integer.compare(a[0], b[0]));\n              count = 0, end = Integer.MIN_VALUE;\n              for (int[] interval : intervals) {\n                  if (interval[0] \u003e= end) {\n                      count++;\n                      end = interval[1];\n                  }\n              }\n              return count;\n![alt text](https://www.quizzcreator.com/img/QUIZ/quiz/60b2236b8c9666.00493324.173.2077.jpg);\n## Backtracking Pattern 🎲 -\u003e\n      ❓ FIND ALL PERMUTATIONS COMBINATIONS SUBSETS PARTIONING \n      🐣 N-Queens Problem, Sudoku Solver, Rat in a Maze, Knight's Tour Problem, Hamiltonian Cycle, Subset Sum Problem, Permutations, Combination Sum, Palindrome Partitioning, Word Break Problem, etc.\n\n      🎭 PsuendoCode Backtracking Pattern 🎲\n        ⏰: O(n!) 🪐: O(n)\n  \n              function backtrack(n, ArrayList\u003cInteger\u003e nums, List\u003cList\u003cInteger\u003e\u003e output, first) {\n                  // if all integers are used up\n                  if (first == n)\n                      output.add(new ArrayList\u003cInteger\u003e(nums));\n                  for (i = first; i \u003c n; i++) {\n                      // place i-th integer first \n                      // in the current permutation\n                      Collections.swap(nums, first, i);\n                      // use next integers to complete the permutations\n                      backtrack(n, nums, output, first + 1);\n                      // backtrack\n                      Collections.swap(nums, first, i);\n                  }\n![alt text](https://ibpublicimages.s3-us-west-2.amazonaws.com/tutorial/backtracking1.png);\n## Dynamic Programming Pattern 📈 -\u003e\n      ❓ FIND OPTIMAL SOLUTION TO COMPLEX PROBLEMS MIN MAX OR COUNT OF GIVEN CONSTRAINTS\n      🐣 Fibonacci Numbers, House Thief, Minimum Coin Change, House Painters, Palindromic Subsequence, Longest Common Subsequence, Longest Increasing Subsequence, Longest Common Substring, Edit Distance, 0/1 Knapsack Problem, Subset Sum Problem, Unbounded Knapsack Problem, Rod Cutting, Word Break Problem, etc.\n\n      🎭 PsuendoCode Dynamic Programming Pattern 📈\n        ⏰: O(n) 🪐: O(n)\n  \n              int[] dp = new int[n + 1];\n              dp[0] = 1;\n              dp[1] = 1;\n              for (i = 2; i \u003c= n; i++)\n                  dp[i] = dp[i - 1] + dp[i - 2];\n              return dp[n];\n![alt text](https://imgs.developpaper.com/imgs/51946-20190827144809463-5507841.png);\n## 🧩 Bit Manipulation Pattern 🧩 -\u003e\n    1️⃣ Bitwise XOR\n      ❓ FIND IF NUMBER IS POWER OF 2\n      🐣 Power of 2, Bitwise AND of Numbers Range, etc.\n\n      🎭 PsuendoCode 🧩 Bit Manipulation Pattern 🧩\n        ⏰: O(1) 🪐: O(1)\n              return (n \u0026 (n - 1)) == 0;\n\n      ❓ FIND UNIQUE NUMBER IN ARRAY OF PAIRS\n      🐣 Single Number, Find the Missing Number, Find the Duplicate Number, Find the Corrupt Pair, etc.\n    2️⃣ Bitwise AND\n      🎭 PsuendoCode Bitwise XOR Pattern 🧩\n        ⏰: O(n) 🪐: O(1)\n              int n = nums.length;\n              for (i = 0; i \u003c n; i++)\n                  x1 = x1 ^ nums[i];\n              for (i = 1; i \u003c= n + 1; i++)\n                  x2 = x2 ^ i;\n              return x1 ^ x2;\n    3️⃣ Bitwise OR\n      ❓ FIND IF NUMBER IS POWER OF 4\n      🐣 Power of 4, etc.\n       🎭 PsuendoCode Bitwise OR Pattern 🧩\n        ⏰: O(1) 🪐: O(1)\n              return (n \u003e 0) \u0026\u0026 ((n \u0026 (n - 1)) == 0) \u0026\u0026 ((n \u0026 0xAAAAAAAA) == 0);\n\n![alt text](https://miro.medium.com/max/620/1*CxPeaIX4QxILRzucksVCsw.png);\n\n      4️⃣ Bitwise Left Shift\n        ❓ FIND IF NUMBER IS POWER OF 2\n        🐣 Power of 2, etc.\n          🎭 PsuendoCode Bitwise Left Shift Pattern 🧩\n            ⏰: O(1) 🪐: O(1)\n                  return (n \u003e 0) \u0026\u0026 ((n \u0026 (n - 1)) == 0);\n\n![alt text](https://cdn.educba.com/academy/wp-content/uploads/2020/05/Left-Shift-Operator-in-C-01.png);\n        \n    5️⃣ Bitwise Right Shift\n      ❓ FIND IF NUMBER IS POWER OF 2\n      🐣 Power of 2, etc.\n        🎭 PsuendoCode Bitwise Right Shift Pattern 🧩\n          ⏰: O(1) 🪐: O(1)\n                return (n \u003e 0) \u0026\u0026 ((n \u0026 (n - 1)) == 0);\n![alt text](https://he-s3.s3.amazonaws.com/media/uploads/5f05f51.jpg);\n##  📐 Matrix Pattern 📐 -\u003e\n      ❓ FIND IF MATRIX IS SINGULAR\n      🐣 Matrix Chain Multiplication, etc.\n\n      🎭 PsuendoCode  📐 Matrix Pattern 📐\n        ⏰: O(n^3) 🪐: O(n^2)\n              int n = matrix.length;\n              for (i = 0; i \u003c n; i++) {\n                  if (matrix[i][i] == 0) {\n                      boolean zeroRow = true;\n                      for (j = 0; j \u003c n; j++) {\n                          if (matrix[i][j] != 0) {\n                              zeroRow = false;\n                              break;\n                          }\n                      }\n                      if (zeroRow) return true;\n                      boolean zeroColumn = true;\n                      for (j = 0; j \u003c n; j++) {\n                          if (matrix[j][i] != 0) {\n                              zeroColumn = false;\n                              break;\n                          }\n                      }\n                      if (zeroColumn) return true;\n                  }\n              }\n              return false;\n![alt text](https://www.geeksforgeeks.org/wp-content/uploads/strassen_new.png);\n## 📘 Trie Pattern 📘 -\u003e\n      ❓ FIND ALL WORDS WITH GIVEN PREFIX\n      🐣 Word Search, Word Break Problem, etc.\n\n      🎭 PsuendoCode 📘 Trie Pattern 📘\n        ⏰: O(n) 🪐: O(n)\n              TrieNode root = new TrieNode();\n              for (String word : words) {\n                  TrieNode node = root;\n                  for (char letter : word.toCharArray()) {\n                      if (node.children[letter - 'a'] == null)\n                          node.children[letter - 'a'] = new TrieNode();\n                      node = node.children[letter - 'a'];\n                  }\n                  node.word = word;\n              }\n              return root;\n![alt text](https://miro.medium.com/max/630/1*f89l46VKjKPgnecqOw4V_w.png);\n\n\n# 75 BLIND CURATED LEETCODE QUESTIONS: \n## Array\n## [Two Sum](https://leetcode.com/problems/two-sum/) #1 👯 \n        ❓: Given an array of integers nums \u0026 an integer target, return indices of the two numbers such that they add up to target.\n        🐣: Given nums = [2, 7, 11, 15], target = 9, Because nums[0] + nums[1] = 2 + 7 = 9, return [0, 1].\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n        🐇 Solution: 👯 Two Pointers  ⏰: O(NlogN) 🪐: O(1)\n\n        var twoSum = function(nums, target) {\n            var twoSum = function(nums, target) {\n            let checkSum = new Map();\n            for(let i=0; i\u003cnums.length; i++){\n            var curr = nums[i];\n            let diff = target-nums[i];\n            if(checkSum.get(diff)){\n                if(checkSum.get(diff)[0] === curr) {\n                 return [checkSum.get(diff)[1], i ];\n                } \n            } else {\n            checkSum.set(nums[i], [diff, i]);\n            }\n        }\n            return checkSum\n        };\n\n## [Best Time to Buy \u0026 Sell Stock](https://leetcode.com/problems/best-time-to-buy-\u0026-sell-stock/) #121 📈\n        ❓: You are given an array prices where prices[i] is the price of a given stock on the ith day.\n        You want to maximize your profit by choosing a single day to buy one stock \u0026 choosing a different day in the future to sell that stock.\n        Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.\n        🐣: Input: prices = [7,1,5,3,6,4], Output: 5, Explain: Buy on day 2 (price = 1) \u0026 sell on day 5 (price = 6), profit = 6-1 = 5. Not 7-1 = 6, as selling price needs to be larger than buying price.\n \n        🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n        🐇 Solution:  📈 Dynamic Programming Pattern Kadane's Algorithm ⏰: O(N) 🪐: O(1)\n\n        var maxProfit = function(prices) {\n            let min = prices[0];\n            let max = 0;\n            for(let i=1; i\u003cprices.length; i++){\n                if(prices[i] \u003c min){\n                    min = prices[i];\n                } else {\n                    max = Math.max(max, prices[i]-min);\n                }\n            }\n            return max;\n        };\n\n## [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/) 👯 \n        Problem : Given Arr [] of int. Return true if has duplicates  : \n        Parameters: Ex 1: Input: nums = [1,2,3,1] Output: true. Ex 2: Input: nums = [1,2,3,4] Output: false. \n         \n        🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n        🐇 Solution:  👯 Two Pointers   ⏰: O(N) 🪐: O(1)\n\n        var containsDuplicate = function(nums) {\n            let checkSum = new Map();\n            for(let i=0; i\u003cnums.length; i++){\n                if(checkSum.get(nums[i])){\n                    return true;\n                } else {\n                    checkSum.set(nums[i], 1);\n                }\n            }\n            return false;\n        };\n\n        var containsDuplicate = function(nums) {\n            return [...new Set(nums)].length !== nums.length;\n        };  \n\n## [Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/) #238 👯 \n        ❓: Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i].\n        The product of any prefix or suffix of nums is guaranteed to fit in a 32-bit integer.\n        You must write an algorithm that runs in O(n) time \u0026 without using the division operation.\n        🐣: Input: nums = [1,2,3,4], Output: [24,12,8,6]\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n        🐇 Solution:  👯 Two Pointers  ⏰: O(N) 🪐: O(1)\n        \n        var productExceptSelf = function(nums) {\n            let result = [];\n            let left = 1;\n            let right = 1;\n            for(let i=0; i\u003cnums.length; i++){\n                result[i] = left;\n                left *= nums[i];\n            }\n            for(let i=nums.length-1; i\u003e=0; i--){\n                result[i] *= right;\n                right *= nums[i];\n            }\n            return result;\n        };\n\n## [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/) #53 📈\n        ❓: Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum \u0026 return its sum.\n        🐣: Input: nums = [-2,1,-3,4,-1,2,1,-5,4], Output: 6, Explain: [4,-1,2,1] has the largest sum = 6.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n        🐇 Solution: 📈 Dynamic Programming Pattern Kadane's Algorithm ⏰: O(N) 🪐: O(1)\n\n        var maxSubArray = function(nums) {\n            let max = nums[0];\n            let curr = nums[0];\n            for(let i=1; i\u003cnums.length; i++){\n                curr = Math.max(nums[i], curr+nums[i]);\n                max = Math.max(max, curr);\n            }\n            return max;\n        };\n\n## [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) #152  📈\n        ❓: Given an integer array nums, find a contiguous non-empty subarray within the array that has the largest product, \u0026 return the product.\n        It is guaranteed that the answer will fit in a 32-bit integer.\n        A subarray is a contiguous subsequence of the array.\n        🐣: Input: nums = [2,3,-2,4], Output: 6, Explain: [2,3] has the largest product 6.\n       \n       🐢 Solution: 🔨 Brute Force ⏰: O(N^2) 🪐: O(1)\n       🐇 Solution: 📈 Dynamic Programming Pattern Kadane's Algorithm ⏰: O(N) 🪐: O(1)\n\n        var maxProduct = function(nums) {\n            let max = nums[0];\n            let min = nums[0];\n            let result = nums[0];\n            for(let i=1; i\u003cnums.length; i++){\n                let temp = max;\n                max = Math.max(nums[i], Math.max(max*nums[i], min*nums[i]));\n                min = Math.min(nums[i], Math.min(temp*nums[i], min*nums[i]));\n                result = Math.max(result, max);\n            }\n            return result;\n        };\n## [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) #153  🏁🔚\n        ❓: Suppose an array of length n sorted in ascending order is rotated between 1 \u0026 n times. For example, the array nums = [0,1,2,4,5,6,7] might become:\n        [4,5,6,7,0,1,2] if it was rotated 4 times.\n        [0,1,2,4,5,6,7] if it was rotated 7 times.\n        Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].\n        Given the sorted rotated array nums of unique elements, return the minimum element of this array.\n        🐣: Input: nums = [3,4,5,1,2], Output: 1\n\n        🐢 Solution: 🔨 Brute Force  ⏰: O(N) 🪐: O(1)\n        🐇 Solution:  🏁🔚  Mod Binary Search Pattern ⏰: O(logN) 🪐: O(1)\n\n        Pattern: 🏁🔚  Mod Binary Search\n        var findMin = function(nums) {\n            let left = 0;\n            let right = nums.length-1;\n            while(left \u003c right){\n                let mid = Math.floor((left+right)/2);\n                if(nums[mid] \u003e nums[right]){\n                    left = mid+1;\n                } else {\n                    right = mid;\n                }\n            }\n            return nums[left];\n        };\n## [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) #153 🏁🔚 \n        ❓: Suppose an array of length n sorted in ascending order is rotated between 1 \u0026 n times. For example, the array nums = [0,1,2,4,5,6,7] might become:\n        [4,5,6,7,0,1,2] if it was rotated 4 times.\n        [0,1,2,4,5,6,7] if it was rotated 7 times.\n        Notice that rotating an array [a[0], a[1], a[2], ..., a[n-1]] 1 time results in the array [a[n-1], a[0], a[1], a[2], ..., a[n-2]].\n        Given the sorted rotated array nums of unique elements, return the minimum element of this array.\n        🐣: Input: nums = [3,4,5,1,2], Output: 1\n\n        🐢 Solution: 🔨 Brute Force  ⏰: O(N) 🪐: O(1)\n        🐇 Solution:  🏁🔚  Mod Binary Search ⏰: O(logN) 🪐: O(1)\n\n        var findMin = function(nums) {\n            let left = 0;\n            let right = nums.length-1;\n            while(left \u003c right){\n                let mid = Math.floor((left+right)/2);\n                if(nums[mid] \u003e nums[right]){\n                    left = mid+1;\n                } else {\n                    right = mid;\n                }\n            }\n            return nums[left];\n        };\n## [Search in Rotated Sorted Array](https://leetcode.com/problems/search-in-rotated-sorted-array/) #33  🏁🔚\n        ❓: You are given an integer array nums sorted in ascending order, \u0026 an integer target.\n        Suppose that nums is rotated at some pivot unknown to you beforeh\u0026 (i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).\n        If target is found in the array return its index, otherwise, return -1.\n        🐣: Input: nums = [4,5,6,7,0,1,2], target = 0, Output: 4\n\n          🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n          🐇 Solution: 🏁🔚  Mod Binary Search ⏰: O(logn) 🪐: O(1)   \n          \n        var search = function(nums, target) {\n            let left = 0;\n            let right = nums.length-1;\n            while(left \u003c= right){\n                let mid = Math.floor((left+right)/2);\n                if(nums[mid] === target){\n                    return mid;\n                } else if(nums[mid] \u003e= nums[left]){\n                    if(target \u003e= nums[left] \u0026\u0026 target \u003c nums[mid]){\n                        right = mid-1;\n                    } else {\n                        left = mid+1;\n                    }\n                } else {\n                    if(target \u003e nums[mid] \u0026\u0026 target \u003c= nums[right]){\n                        left = mid+1;\n                    } else {\n                        right = mid-1;\n                    }\n                }\n            }\n            return -1;\n        };\n## [3Sum](https://leetcode.com/problems/3sum/) #15 👯\n        ❓: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, \u0026 j != k, \u0026 nums[i] + nums[j] + nums[k] == 0.\n        Notice that the solution set must not contain duplicate triplets.\n        🐣: Input: nums = [-1,0,1,2,-1,-4], Output: [[-1,-1,2],[-1,0,1]]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(N^3)   🪐: O(1)\n        🐇 Solution: 👯 Two Pointers  ⏰: O(N^2)   🪐: O(N)\n\n        var threeSum = function(nums) {\n            let result = [];\n            nums.sort((a,b) =\u003e a-b);\n            for(let i=0; i\u003cnums.length-2; i++){\n                if(i \u003e 0 \u0026\u0026 nums[i] === nums[i-1]) continue;\n                let left = i+1;\n                let right = nums.length-1;\n                while(left \u003c right){\n                    let sum = nums[i] + nums[left] + nums[right];\n                    if(sum === 0){\n                        result.push([nums[i], nums[left], nums[right]]);\n                        while(left \u003c right \u0026\u0026 nums[left] === nums[left+1]) left++;\n                        while(left \u003c right \u0026\u0026 nums[right] === nums[right-1]) right--;\n                        left++;\n                        right--;\n                    } else if(sum \u003c 0){\n                        left++;\n                    } else {\n                        right--;\n                    }\n                }\n            }\n            return result;\n        };\n## [Container With Most Water](https://leetcode.com/problems/container-with-most-water/) #11 👯 \n        ❓: Given n non-negative integers a1, a2, ..., an , where each represents a poat coordinate (i, ai) n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) \u0026 (i, 0) Find two lines, which, together with the x-axis forms a container, such that the container contains the most water\n        Notice that you may not slant the container.\n        🐣: Input: height = [1,8,6,2,5,4,8,3,7], Output: 49\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n^2) 🪐: O(1)\n        🐇 Solution:  👯 Two Pointers ⏰: O(n) 🪐: O(1)\n\n        var maxArea = function(height) {\n            let left = 0;\n            let right = height.length-1;\n            let max = 0;\n            while(left \u003c right){\n                let area = Math.min(height[left], height[right]) * (right-left);\n                max = Math.max(max, area);\n                if(height[left] \u003c height[right]){\n                    left++;\n                } else {\n                    right--;\n                }\n            }\n            return max;\n        };\n\n---\n\n## Binary \n\n## [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/) 🧩 \n      ❓: Given two integers a \u0026 b, return sum of the two integers without using the operators + \u0026 -.\n      🐣: 1️⃣ Input: a = 1, b = 2. Output: 3 2️⃣ Input: a = 2, b = 3 Output: 5.\n        \n          🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n          🐇 Solution: 🧩 Bit Manipulation ⏰: O(1)  🪐: O(1)\n\n            var getSum = function(a, b) {\n                let carry; // store carry \n                while(a!==0){\n                    carry = a \u0026 b;\n                    b = a ^ b;\n                    a = carry \u003c\u003c 1;\n                }\n                return b  \n            };\n## [Divide Two Integers](https://leetcode.com/problems/divide-two-integers/) #29 🧩 \n      ❓: Given two integers dividend \u0026 divisor, divide two integers without using multiplication, division, \u0026 mod operator.\n      Return the quotient after dividing dividend by divisor.\n      The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 \u0026 truncate(-2.7335) = -2.\n      Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For this problem, assume that your function returns 231 − 1 when the division result overflows.\n      🐣: Input: dividend = 10, divisor = 3, Output: 3\n\n          🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n          🐇 Solution: 🧩 Bit Manipulation ⏰: O(logn)   🪐: O(logn)\n\n          var divide = function(dividend, divisor) {\n              if (dividend === 0 || divisor === 0) return 0\n              let isNegative = false;\n              let quotient = 0;\n              if ((divisor \u003c 0 || dividend \u003c 0) \u0026\u0026 !(divisor \u003c 0 \u0026\u0026 dividend \u003c 0)) isNegative = true;\n              dividend = Math.abs(dividend)\n              divisor = Math.abs(divisor)\n              while (dividend \u003e= divisor) {\n                  let carry = 1, tempDividend= dividend, tempDivisor = divisor\n                  while (tempDivisor \u003c= (tempDividend\u003e\u003e 1)){\n                      carry \u003c\u003c= 1\n                      tempDividend\u003e\u003e= 1\n                      tempDivisor \u003c\u003c= 1\n                  }\n                  quotient += carry\n                  dividend -= tempDivisor\n              }\n              if (isNegative) return -quotient\n              if (quotient \u003e= 2**31) {\n                  return 2**31 - 1\n              }\n              return quotient\n          };\n## [Number of 1 Bits](https://leetcode.com/problems/number-of-1-bits/) #191 🧩 \n        ❓: Write a function that takes an unsigned integer \u0026 returns the number of '1' bits it has (aka Hamming weight).\n        🐣: 1️⃣ Input: n = 00000000000000000000000000001011 Output: 3 . N as a total of three '1' bits.2️⃣ Input: n = 00000000000000000000000010000000 Output: 1 3️⃣ Input: n = 11111111111111111111111111111101 Output: 31\n\n            🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n            🐇 Solution: 🧩 Bit Manipulation ⏰: O(1) 🪐: O(1)\n\n            var hammingWeight = function(n) {\n                let count = 0;\n                while(n!=0){\n                    n = n\u0026(n-1); //mask\u003c\u003c1\n                    count++;\n                }\n                return count\n            };\n\n## [Counting Bits](https://leetcode.com/problems/counting-bits/) #338 🧩 \n        ❓: Given an integer n, return an array ans of length n + 1 such that for each i (0 \u003c= i \u003c= n), ans[i] is the number of 1's in the binary representation of i.\n        🐣: 1️⃣ Input: n = 2 Output: [0,1,1]  Explain: 0 --\u003e 0 1 --\u003e 1 2 --\u003e 10 2️⃣ Input: n = 5 Output: [0,1,1,2,1,2]\n\n            🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n            🐇 Solution: 🧩 Bit Manipulation ⏰: O(N) 🪐: O(1)\n\n            var countBits = function(n) {\n                let result = [0];\n                for(let i = 1; i \u003c= n; i++){\n                    result.push(result[i\u003e\u003e1] + (i\u00261));\n                }\n                return result;\n            };\n            \n            🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(N)\n            🐇 Solution: 🧩 Bit Manipulation  ⏰: O(n)  🪐: O(n)\n\n            const countBits = (n) =\u003e {\n                const res = new Array(n);\n                res[0] = 0;\n\n                for (let i = 1; i \u003c= n; i++) {\n                    if (i % 2 === 0) res[i] = res[i / 2];\n                    else res[i] = res[i - 1] + 1;\n                }\n\n                return res;\n            };\n## [Missing Number](https://leetcode.com/problems/missing-number/) #268 🧩\n        ❓: Given an [] containing n distinct numbers in the range [0, n], return the only num in the range tht missing from the []\n        🐣: 1️⃣ Input: nums = [3,0,1] Output: 2 Explain: n = 3 since there are 3 num, so all n are in range [0,3]. 2 is the missing num in the range it does not appear in nums. 2️⃣ Input: nums = [0,1] Output: 2 3️⃣ Input: nums = [9,6,4,2,3,5,7,0,1] Output: 8\n\n            🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(N)\n            🐇 Solution: 🧩 Bit Manipulation  ⏰: O(n)  🪐: O(n)\n\n            var missingNumber = function (nums) {\n              let i = 0;\n              let temp = 0;\n              while (i \u003c nums.length) {\n                if (nums[i] != i \u0026\u0026 nums.length \u003e nums[i]) {\n                  temp = nums[nums[i]];\n                  nums[nums[i]] = nums[i];\n                  nums[i] = temp;\n                } else {\n                  i++;\n                }\n              }\n\n              for (let i = 0; i \u003c nums.length; i++) {\n                if (i != nums[i]) return i;\n              }\n\n              return nums.length;\n            };\n\n## [Reverse Bits](https://leetcode.com/problems/reverse-bits/) #190 🧩\n        ❓: Reverse bits of a given 32 bits unsigned integer.\n        🐣: 1️⃣ Input: n = 00000010100101000001111010011100 Output: 964176192 (00111001011110000010100101000000)\n        Explain: The input binary string 00000010100101000001111010011100 represents the unsigned integer 43261596, so return 964176192 which its binary representation is 00111001011110000010100101000000. 2️⃣ Input: n = 11111111111111111111111111111101\n        Output:   3221225471 (10111111111111111111111111111111)\n\n            🐢 Solution: 🔨 Brute Force ⏰: O(N) 🪐: O(1)\n            🐇 Solution: 🧩 Bit Manipulation ⏰: O(1)  🪐: O(1)\n\n            var reverseBits = function (n) {\n              var len = 32;\n              var arr = new Array();\n              while (len \u003e 0) {\n                var t = n \u0026 1;\n                n = n \u003e\u003e 1;\n                arr.push(t);\n                len--;\n              }\n              var res = arr.join(\"\");\n              return parseInt(res, 2);\n            };\n\n## 📈 Dynamic Programming\n\n## [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/) #70  📈\n        ❓: You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?\n        🐣: 1️⃣ Input: n = 2 Output: 2. Explain: There are two ways to climb to the top. 1. 1 step + 1 step 2. 2 steps\n        2️⃣ Input: n = 3 Output: 3. Explain: There are three ways to climb to the top. 1. 1 step + 1 step + 1 step 2. 1 step + 2 steps 3. 2 steps + 1 step\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n) 🪐: O(n)\n\n            var climbStairs = function (n) {\n              if (n == 1) return 1;\n              if (n == 2) return 2;\n              let dp = new Array(n + 1); // ways to climb array\n              dp[1] = 1;\n              dp[2] = 2;\n              for (let i = 3; i \u003c= n; i++) { //Either climb 1 stair \u0026 then climb the rest i-1 stairs X ways.\n                dp[i] = dp[i - 1] + dp[i - 2]; //- Or climb 2 stairs at once \u0026 then climb the rest i-2 stairs Y ways.\n              }                                  //Total: X + Y ways\n              return dp[n]; \n            };\n## [Coin Change](https://leetcode.com/problems/coin-change/) #322 📈\n        ❓: You are given an integer array coins representing coins of different denominations \u0026 an integer amount representing a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return -1.\n        🐣: 1️⃣ Input: coins = [1,2,5], amount = 11 Output: 3 Explain: 11 = 5 + 5 + 1\n        2️⃣ Input: coins = [2], amount = 3 Output: -1\n        3️⃣ Input: coins = [1], amount = 0 Output: 0\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n^amount) 🪐: O(amount)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n^amount) 🪐: O(n^amount)   \n\n            var coinChange = function (coins, amount) {\n              let dp = new Array(amount + 1).fill(amount + 1);\n              dp[0] = 0;\n              for (let i = 1; i \u003c= amount; i++) {\n                for (let j = 0; j \u003c coins.length; j++) {\n                  if (coins[j] \u003c= i) {\n                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);\n                  }\n                }\n              }\n              return dp[amount] \u003e amount ? -1 : dp[amount];\n            };\n## [Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) #300  📈\n        ❓: Given an integer array nums, return the length of the longest strictly increasing subsequence.\n        🐣: 1️⃣ Input: nums = [10,9,2,5,3,7,101,18] Output: 4 Explain: The longest increasing subsequence is [2,3,7,101], therefore the length is 4. 2️⃣ Input: nums = [0,1,0,3,2,3] Output: 4 3️⃣ Input: nums = [7,7,7,7,7,7,7] Output: 1\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n^2) 🪐: O(n^2)        \n\n            var lengthOfLIS = function (nums) {\n              let dp = new Array(nums.length).fill(1);\n              let max = 1;\n              for (let i = 1; i \u003c nums.length; i++) {\n                for (let j = 0; j \u003c i; j++) {\n                  if (nums[i] \u003e nums[j]) {\n                    dp[i] = Math.max(dp[i], dp[j] + 1);\n                    max = Math.max(max, dp[i]);\n                  }\n                }\n              }\n              return max;\n            };\n\n## [Longest Common Subsequence](https://leetcode.com/problems/longest-common-subsequence/) #1143  📈\n        ❓: Given two strings text1 \u0026 text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with some characters(can be none) deleted without changing the relative order of the remaining characters. (eg, \"ace\" is a subsequence of \"abcde\" while \"aec\" is not). A common subsequence of two strings is a subsequence that is common to both strings.\n        🐣: 1️⃣ Input: text1 = \"abcde\", text2 = \"ace\" Output: 3 Explain: The longest common subsequence is \"ace\" \u0026 its length is 3. 2️⃣ Input: text1 = \"abc\", text2 = \"abc\" Output: 3 3️⃣ Input: text1 = \"abc\", text2 = \"def\" Output: 0\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(m*n) 🪐: O(m*n)\n\n            var longestCommonSubsequence = function (text1, text2) {\n              let dp = new Array(text1.length + 1)\n                .fill(0)\n                .map(() =\u003e new Array(text2.length + 1).fill(0));\n              for (let i = 1; i \u003c= text1.length; i++) {\n                for (let j = 1; j \u003c= text2.length; j++) {\n                  if (text1[i - 1] == text2[j - 1]) {\n                    dp[i][j] = dp[i - 1][j - 1] + 1;\n                  } else {\n                    dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);\n                  }\n                }\n              }\n              return dp[text1.length][text2.length];\n            };\n## [Word Break Problem](https://leetcode.com/problems/word-break/)📈\n        ❓: Given a string s \u0026 a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary words. Note that the same word in the dictionary may be reused multiple times in the segmentation.\n        🐣: 1️⃣ Input: s = \"leetcode\", wordDict = [\"leet\",\"code\"] Output: true Explain: Return true because \"leetcode\" can be segmented as \"leet code\". 2️⃣ Input: s = \"applepenapple\", wordDict = [\"apple\",\"pen\"] Output: true Explain: Return true because \"applepenapple\" can be segmented as \"apple pen apple\". Note that you are allowed to reuse a dictionary word. 3️⃣ Input: s = \"cats\u0026og\", wordDict = [\"cats\",\"dog\",\"s\u0026\",\"\u0026\",\"cat\"] Output: false\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n^2) 🪐: O(n^2)\n\n            var wordBreak = function (s, wordDict) {\n              let dp = new Array(s.length + 1).fill(false);\n              dp[0] = true;\n              for (let i = 1; i \u003c= s.length; i++) {\n                for (let j = 0; j \u003c i; j++) {\n                  if (dp[j] \u0026\u0026 wordDict.includes(s.substring(j, i))) {\n                    dp[i] = true;\n                    break;\n                  }\n                }\n              }\n              return dp[s.length];\n            };\n## [Combination Sum](https://leetcode.com/problems/combination-sum-iv/) #377 📈\n        ❓: Given an integer array with all positive numbers \u0026 no duplicates, find the number of possible combinations that add up to a positive integer target. \n        🐣: Input: nums = [1, 2, 3] target = 4 Output: 7 Explain: The possible combination ways are: (1, 1, 1, 1) (1, 1, 2) (1, 2, 1) (1, 3) (2, 1, 1) (2, 2) (3, 1) Note that different sequences are counted as different combinations. Therefore the output is 7.\n      \n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n*target) 🪐:  O(n*target)\n\n            var combinationSum4 = function (nums, target) {\n              let dp = new Array(target + 1).fill(0);\n              dp[0] = 1;\n              for (let i = 1; i \u003c= target; i++) {\n                for (let j = 0; j \u003c nums.length; j++) {\n                  if (nums[j] \u003c= i) {\n                    dp[i] += dp[i - nums[j]];\n                  }\n                }\n              }\n              return dp[target];\n            };\n## [House Robber](https://leetcode.com/problems/house-robber/) #198\n        ❓: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constrastopping you from robbing each of them is that adjacent houses have security system connected \u0026 it will automatically contact the police if two adjacent houses were broken into on the same night. Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.\n        🐣: 1️⃣ Input: nums = [1,2,3,1] Output: 4 Explain: Rob house 1 (money = 1) \u0026 then rob house 3 (money = 3). Total amount you can rob = 1 + 3 = 4. 2️⃣ Input: nums = [2,7,9,3,1] Output: 12 Explain: Rob house 1 (money = 2), rob house 3 (money = 9) \u0026 rob house 5 (money = 1). Total amount you can rob = 2 + 9 + 1 = 12.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n) 🪐: O(n)\n\n            var rob = function (nums) {\n              let dp = new Array(nums.length + 1).fill(0);\n              dp[0] = 0;\n              dp[1] = nums[0];\n              for (let i = 2; i \u003c= nums.length; i++) {\n                dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i - 1]);\n              }\n              return dp[nums.length];\n            };\n## [House Robber II](https://leetcode.com/problems/house-robber-ii/) #213\n\n        ❓: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have security system connected \u0026 it will automatically contact the police if two adjacent houses were broken into on the same night. Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.\n        🐣: 1️⃣ Input: nums = [2,3,2] Output: 3 Explain: You cannot rob house 1 (money = 2) \u0026 then rob house 3 (money = 2), because they are adjacent houses. 2️⃣ Input: nums = [1,2,3,1] Output: 4 Explain: Rob house 1 (money = 1) \u0026 then rob house 3 (money = 3). Total amount you can rob = 1 + 3 = 4. 3️⃣ Input: nums = [0] Output: 0\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n) 🪐: O(n)\n\n            var rob = function (nums) {\n              if (nums.length == 1) return nums[0];\n              return Math.max(\n                robRange(nums, 0, nums.length - 2),\n                robRange(nums, 1, nums.length - 1)\n              );\n            };\n            var robRange = function (nums, start, end) {\n              let dp = new Array(nums.length + 1).fill(0);\n              dp[start] = nums[start];\n              dp[start + 1] = Math.max(nums[start], nums[start + 1]);\n              for (let i = start + 2; i \u003c= end; i++) {\n                dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);\n              }\n              return dp[end];\n            };\n## [Decode Ways](https://leetcode.com/problems/decode-ways/) #91 📈\n        ❓: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -\u003e 1 'B' -\u003e 2 ... 'Z' -\u003e 26 Given a non-empty string s containing only digits, determine the total number of ways to decode it. The answer is guaranteed to fit in a 32-bit integer.\n        🐣: 1️⃣ Input: s = \"12\" Output: 2 Explain: It could be decoded as \"AB\" (1 2) or \"L\" (12). 2️⃣ Input: s = \"226\" Output: 3 Explain: It could be decoded as \"BZ\" (2 26), \"VF\" (22 6), or \"BBF\" (2 2 6). 3️⃣ Input: s = \"0\" Output: 0 Explain: There is no character that is mapped to a number starting with 0. The only valid mappings with 0 are 'J' -\u003e \"10\" \u0026 'T' -\u003e \"20\", neither of which start with 0. Hence, there are no valid ways to decode this since all digits need to be mapped. #4 Input: s = \"1\" Output: 1\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization  ⏰: O(n) 🪐: O(n)\n\n            var numDecodings = function (s) {\n              if (s[0] == \"0\") return 0;\n              let dp = new Array(s.length + 1).fill(0);\n              dp[0] = 1;\n              dp[1] = 1;\n              for (let i = 2; i \u003c= s.length; i++) {\n                let first = parseInt(s.substring(i - 1, i));\n                let second = parseInt(s.substring(i - 2, i));\n                if (first \u003e= 1 \u0026\u0026 first \u003c= 9) {\n                  dp[i] += dp[i - 1];\n                }\n                if (second \u003e= 10 \u0026\u0026 second \u003c= 26) {\n                  dp[i] += dp[i - 2];\n                }\n              }\n              return dp[s.length];\n            };\n## [Unique Paths](https://leetcode.com/problems/unique-paths/) #62 📈\n\n        ❓: A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The robot can only move either down or right at any poin time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below). How many possible unique paths are there?\n        🐣: 1️⃣ Input: m = 3, n = 7 Output: 28 2️⃣ Input: m = 3, n = 2 Output: 3 Explain: From the top-left corner, there are a total of 3 ways to reach the bottom-right corner: 1. Right -\u003e Down -\u003e Down 2. Down -\u003e Down -\u003e Right 3. Down -\u003e Right -\u003e Down 3️⃣ Input: m = 7, n = 3 Output: 28 #4 Input: m = 3, n = 3 Output: 6\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Memoization ⏰: O(n) 🪐: O(n)\n\n            var uniquePaths = function (m, n) {\n              let dp = new Array(m).fill(0).map(() =\u003e new Array(n).fill(0));\n              for (let i = 0; i \u003c m; i++) {\n                dp[i][0] = 1;\n              }\n              for (let j = 0; j \u003c n; j++) {\n                dp[0][j] = 1;\n              }\n              for (let i = 1; i \u003c m; i++) {\n                for (let j = 1; j \u003c n; j++) {\n                  dp[i][j] = dp[i - 1][j] + dp[i][j - 1];\n                }\n              }\n              return dp[m - 1][n - 1];\n            };\n## [Jump Game](https://leetcode.com/problems/jump-game/) #55 📈\n\n        ❓: Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index.\n        🐣: 1️⃣ Input: nums = [2,3,1,1,4] Output: true Explain: Jump 1 step from index 0 to 1, then 3 steps to the last index. 2️⃣ Input: nums = [3,2,1,0,4] Output: false Explain: You will always arrive at index 3 no matter what. Its maximum jump length is 0, which makes it impossible to reach the last index.\n        \n         🐢 Solution: 🔨 Brute Force ⏰: O(2^n) 🪐: O(n)\n        🐇 Solution:  📈 Dynamic Programming Tabulation ⏰: O(n) 🪐: O(n)\n\n            var canJump = function (nums) {\n              let dp = new Array(nums.length).fill(false);\n              dp[0] = true;\n              for (let i = 1; i \u003c nums.length; i++) {\n                for (let j = 0; j \u003c i; j++) {\n                  if (dp[j] \u0026\u0026 j + nums[j] \u003e= i) {\n                    dp[i] = true;\n                    break;\n                  }\n                }\n              }\n              return dp[nums.length - 1];\n            };\n\n---\n## Graph\n\n## [Clone Graph](https://leetcode.com/problems/clone-graph/) #133 🌳\n       ❓: Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph. Each node in the graph contains a val (int) \u0026 a list (List[Node]) of its neighbors.\n       🐣: 1️⃣ Input: adjList = [[2,4],[1,3],[2,4],[1,3]] Output: [[2,4],[1,3],[2,4],[1,3]] Explain: There are 4 nodes in the graph. 2️⃣ Input: adjList = [[]] Output: [[]] 3️⃣ Input: adjList = [] Output: [] #4 Input: adjList = [[2],[1]] Output: [[2],[1]]\n\n              🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n              🐇 Solution: 🌳 BFS ⏰: O(n) 🪐: O(n)\n\n              var cloneGraph = function (node) {\n                 if (!node) return node;\n                 let map = new Map();\n                 let clone = new Node(node.val, []);\n                 map.set(node, clone);\n                 let queue = [node];\n                 while (queue.length) {\n                let n = queue.shift();\n                for (let neighbor of n.neighbors) {\n                  if (!map.has(neighbor)) {\n                     map.set(neighbor, new Node(neighbor.val, []));\n                     queue.push(neighbor);\n                  }\n                  map.get(n).neighbors.push(map.get(neighbor));\n                }\n                 }\n                 return clone;\n              };\n\n## [Course Schedule](https://leetcode.com/problems/course-schedule/) #207  📅\n        ❓: There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai. For example, the pair [0, 1], indicates that to take course 0 you have to first take course 1. Return true if you can finish all courses. Otherwise, return false.\n        🐣: 1️⃣ Input: numCourses = 2, prerequisites = [[1,0]] Output: true Explain: There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible. 2️⃣ Input: numCourses = 2, prerequisites = [[1,0],[0,1]] Output: false Explain: There are a total of 2 courses to take. To take course 1 you should have finished course 0, \u0026 to take course 0 you should also have finished course 1. So it is impossible.\n          \n          🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n          🐇 Solution:  📅  Topological Sort  ⏰: O(V+E)   🪐: O(V+E) \n\n            var canFinish = function (numCourses, prerequisites) {\n              let graph = new Map();\n              let indegree = new Array(numCourses).fill(0);\n              for (let [course, pre] of prerequisites) {\n                if (!graph.has(pre)) graph.set(pre, []);\n                graph.get(pre).push(course);\n                indegree[course]++;\n              }\n              let queue = [];\n              for (let i = 0; i \u003c indegree.length; i++) {\n                if (indegree[i] == 0) queue.push(i);\n              }\n              let count = 0;\n              while (queue.length) {\n                let course = queue.shift();\n                count++;\n                if (graph.has(course)) {\n                  for (let next of graph.get(course)) {\n                    indegree[next]--;\n                    if (indegree[next] == 0) queue.push(next);\n                  }\n                }\n              }\n              return count == numCourses;\n            };\n\n## [Pacific Atlantic Water Flow](https://leetcode.com/problems/pacific-atlantic-water-flow/) #417 🌳 \n        ❓: Given an m x n matrix of non-negative integers representing the height of each unit cell in a continent, the \"Pacific ocean\" touches the left \u0026 top edges of the matrix \u0026 the \"Atlantic ocean\" touches the right \u0026 bottom edges. Water can only flow in four directions (up, down, left, or right) from a cell to another one with height equal or lower. Find the list of grid coordinates where water can flow to both the Pacific \u0026 Atlantic ocean.\n        🐣: 1️⃣ Input: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]] Output: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]] Explain: Pacific ~ ~ ~ ~ ~ 1 2 2 3 (5) ~ 3 2 3 (4) (4) ~ 2 4 (5) 3 1 ~ (6) (7) 1 4 5 ~ (5) 1 1 2 4 ~ ~ ~ ~ ~ Atlantic 2️⃣ Input: heights = [[2,1],[1,2]] Output: [[0,0],[0,1],[1,0],[1,1]]\n\n            🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n            🐇 Solution: 🌳 BFS ⏰: O(n) 🪐: O(n)\n\n            var pacificAtlantic = function (heights) {\n              let m = heights.length;\n              let n = heights[0].length;\n              let pacific = new Array(m).fill(0).map(() =\u003e new Array(n).fill(false));\n              let atlantic = new Array(m).fill(0).map(() =\u003e new Array(n).fill(false));\n              let queue = [];\n              for (let i = 0; i \u003c m; i++) {\n                queue.push([i, 0]);\n                pacific[i][0] = true;\n              }\n              for (let i = 0; i \u003c n; i++) {\n                queue.push([0, i]);\n                pacific[0][i] = true;\n              }\n              🌳 BFS(heights, pacific, queue);\n              queue = [];\n              for (let i = 0; i \u003c m; i++) {\n                queue.push([i, n - 1]);\n                atlantic[i][n - 1] = true;\n              }\n              for (let i = 0; i \u003c n; i++) {\n                queue.push([m - 1, i]);\n                atlantic[m - 1][i] = true;\n              }\n              🌳 BFS(heights, atlantic, queue);\n              let res = [];\n              for (let i = 0; i \u003c m; i++) {\n                for (let j = 0; j \u003c n; j++) {\n                  if (pacific[i][j] \u0026\u0026 atlantic[i][j]) res.push([i, j]);\n                }\n              }\n              return res;\n            };\n\n            function 🌳 BFS(heights, ocean, queue) {\n              let dirs = [[0, 1], [0, -1], [1, 0], [-1, 0]];\n              while (queue.length) {\n                let [i, j] = queue.shift();\n                for (let dir of dirs) {\n                  let x = i + dir[0];\n                  let y = j + dir[1];\n                  if (\n                    x \u003e= 0 \u0026\u0026\n                    x \u003c heights.length \u0026\u0026\n                    y \u003e= 0 \u0026\u0026\n                    y \u003c heights[0].length \u0026\u0026\n                    !ocean[x][y]\n                  ) {\n                    if (heights[x][y] \u003e= heights[i][j]) {\n                      ocean[x][y] = true;\n                      queue.push([x, y]);\n                    }\n                  }\n                }\n              }\n            }\n\n\n                \n## [Number of Islands](https://leetcode.com/problems/number-of-islands/) #200 🌳\n        Pattern Used: 🌳 BFS Pattern 🌲 DFS Pattern Union Find Pattern\n        ❓: Given an m x n 2d grid map of '1's (l\u0026) \u0026 '0's (water), return the number of islands. An isl\u0026 is surrounded by water \u0026 is formed by connecting adjacent l\u0026s horizontally or vertically. You may assume all four edges of the grid are all surrounded by water.\n        🐣: 1️⃣ Input: grid = [ [\"1\",\"1\",\"1\",\"1\",\"0\"], [\"1\",\"1\",\"0\",\"1\",\"0\"], [\"1\",\"1\",\"0\",\"0\",\"0\"], [\"0\",\"0\",\"0\",\"0\",\"0\"] ] Output: 1 2️⃣ Input: grid = [ [\"1\",\"1\",\"0\",\"0\",\"0\"], [\"1\",\"1\",\"0\",\"0\",\"0\"], [\"0\",\"0\",\"1\",\"0\",\"0\"], [\"0\",\"0\",\"0\",\"1\",\"1\"] ] Output: 3\n       \n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution:  🌳 BFS  ⏰: O(mn) 🪐: O(mn)\n\n            var numIslands = function (grid) {\n              let m = grid.length;\n              let n = grid[0].length;\n              let count = 0;\n              let dirs = [[0, 1], [0, -1], [1, 0], [-1, 0]];\n              for (let i = 0; i \u003c m; i++) {\n                for (let j = 0; j \u003c n; j++) {\n                  if (grid[i][j] == \"1\") {\n                    count++;\n                    grid[i][j] = \"0\";\n                    let queue = [[i, j]];\n                    while (queue.length) {\n                      let [x, y] = queue.shift();\n                      for (let dir of dirs) {\n                        let a = x + dir[0];\n                        let b = y + dir[1];\n                        if (\n                          a \u003e= 0 \u0026\u0026\n                          a \u003c m \u0026\u0026\n                          b \u003e= 0 \u0026\u0026\n                          b \u003c n \u0026\u0026\n                          grid[a][b] == \"1\"\n                        ) {\n                          grid[a][b] = \"0\";\n                          queue.push([a, b]);\n                        }\n                      }\n                    }\n                  }\n                }\n              }\n              return count;\n            };\n## [Longest Consecutive Sequence](https://leetcode.com/problems/longest-consecutive-sequence/) #128  ♾ \n        ❓: Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time.\n        🐣: 1️⃣ Input: nums = [100,4,200,1,3,2] Output: 4 Explain: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. 2️⃣ Input: nums = [0,3,7,2,5,8,4,6,0,1] Output: 9\n\n         🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n         🐇 Solution:  ♾  Union Find  ⏰: O(n) 🪐: O(n)\n\n            var longestConsecutive = function (nums) {\n              let set = new Set(nums);\n              let max = 0;\n              for (let num of set) {\n                if (!set.has(num - 1)) {\n                  let curr = num;\n                  let count = 1;\n                  while (set.has(curr + 1)) {\n                    curr++;\n                    count++;\n                  }\n                  max = Math.max(max, count);\n                }\n              }\n              return max;\n            };\n\n## Interval\n\n## [Insert Interval](https://leetcode.com/problems/insert-interval/) #57 🚗🚙 \n        ❓: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary). You may assume that the intervals were initially sorted according to their start times.\n        🐣: 1️⃣ Input: intervals = [[1,3],[6,9]], newInterval = [2,5] Output: [[1,5],[6,9]] 2️⃣ Input: intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] Output: [[1,2],[3,10],[12,16]] Explain: Because the new interval [4,8] overlaps with [3,5],[6,7],[8,10].\n        \n          🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n          🐇 Solution: 🚗🚙  Merge Intervals  ⏰: O(n) 🪐: O(n)\n  \n              var insert = function (intervals, newInterval) {\n                let res = [];\n                let i = 0;\n                while (i \u003c intervals.length \u0026\u0026 intervals[i][1] \u003c newInterval[0]) {\n                  res.push(intervals[i]);\n                  i++;\n                }\n                while (i \u003c intervals.length \u0026\u0026 intervals[i][0] \u003c= newInterval[1]) {\n                  newInterval[0] = Math.min(newInterval[0], intervals[i][0]);\n                  newInterval[1] = Math.max(newInterval[1], intervals[i][1]);\n                  i++;\n                }\n                res.push(newInterval);\n                while (i \u003c intervals.length) {\n                  res.push(intervals[i]);\n                  i++;\n                }\n                return res;\n              };\n## [Merge Intervals](https://leetcode.com/problems/merge-intervals/) #56 🚗🚙 💰\n        ❓: Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, \u0026 return an array of the non-overlapping intervals that cover all the intervals in the input.\n        🐣: 1️⃣ Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explain: Since intervals [1,3] \u0026 [2,6] overlaps, merge them into [1,6]. 2️⃣ Input: intervals = [[1,4],[4,5]] Output: [[1,5]] Explain: Intervals [1,4] \u0026 [4,5] are considered overlapping.\n        \n          🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n          🐇 Solution: 🚗🚙  Merge Intervals  ⏰: O(n) 🪐: O(n)\n  \n              var merge = function (intervals) {\n                if (intervals.length \u003c= 1) return intervals;\n                intervals.sort((a, b) =\u003e a[0] - b[0]);\n                let res = [intervals[0]];\n                for (let i = 1; i \u003c intervals.length; i++) {\n                  let curr = intervals[i];\n                  let prev = res[res.length - 1];\n                  if (curr[0] \u003c= prev[1]) {\n                    prev[1] = Math.max(prev[1], curr[1]);\n                  } else {\n                    res.push(curr);\n                  }\n                }\n                return res;\n              };\n\n## [Non-overlapping Intervals](https://leetcode.com/problems/non-overlapping-intervals/) #435 🚗🚙\n       ❓: Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.\n        🐣: 1️⃣ Input: intervals = [[1,2],[2,3],[3,4],[1,3]] Output: 1 Explain: [1,3] can be removed \u0026 the rest of the intervals are non-overlapping. 2️⃣ Input: intervals = [[1,2],[1,2],[1,2]] Output: 2 Explain: You need to remove two [1,2] to make the rest of the intervals non-overlapping. 3️⃣ Input: intervals = [[1,2],[2,3]] Output: 0 Explain: You don't need to remove any of the intervals since they're already non-overlapping.\n\n          🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n          🐇 Solution:  🚗🚙  Merge Intervals  ⏰: O(nlogn) 🪐: O(1)\n\n            var eraseOverlapIntervals = function (intervals) {\n              if (intervals.length \u003c= 1) return 0;\n              intervals.sort((a, b) =\u003e a[1] - b[1]);\n              let count = 0;\n              let prev = intervals[0];\n              for (let i = 1; i \u003c intervals.length; i++) {\n                let curr = intervals[i];\n                if (curr[0] \u003c prev[1]) {\n                  count++;\n                } else {\n                  prev = curr;\n                }\n              }\n              return count;\n            };\n---\n\n## Linked List\n\n## [Reverse a Linked List](https://leetcode.com/problems/reverse-linked-list/) #206  🐰\u0026🐢 \n        ❓: Given the head of a singly linked list, reverse the list, \u0026 return the reversed list.\n        🐣: 1️⃣ Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] 2️⃣ Input: head = [1,2] Output: [2,1] 3️⃣ Input: head = [] Output: []\n        \n        🐢 Solution: 🔨 Brute Force ⏰: 🔨 Brute Force ⏰:\n        🐇 Solution: 🐰\u0026🐢 Fast \u0026 Slow Pointers  ⏰: O(n) 🪐: O(1)\n\n            var reverseList = function (head) {\n              let prev = null;\n              let curr = head;\n              while (curr) {\n                let next = curr.next;\n                curr.next = prev;\n                prev = curr;\n                curr = next;\n              }\n              return prev;\n            };\n            which algorithm from ./algorithms.md is used in this solution?\n           the \n## [Detect Cycle in a Linked List](https://leetcode.com/problems/linked-list-cycle/) #141 🐰\u0026🐢 \n        ❓: Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected to. Note that pos is not passed as a parameter. Return true if there is a cycle in the linked list. Otherwise, return false.\n        🐣: 1️⃣ Input: head = [3,2,0,-4], pos = 1 Output: true Explain: There is a cycle in the linked list, where the tail connects to the 1st node (0-indexed). 2️⃣ Input: head = [1,2], pos = 0 Output: true Explain: There is a cycle in the linked list, where the tail connects to the 0th node. 3️⃣ Input: head = [1], pos = -1 Output: false Explain: There is no cycle in the linked list.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution:  🐰\u0026🐢 Fast \u0026 Slow Pointers  ⏰: O(n) 🪐: O(1)\n\n            var hasCycle = function (head) {\n              let slow = head;\n              let fast = head;\n              while (fast \u0026\u0026 fast.next) {\n                slow = slow.next;\n                fast = fast.next.next;\n                if (slow === fast) return true;\n              }\n              return false;\n            };\n## [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) #21 🐰\u0026🐢 \n        ❓: Merge two sorted linked lists \u0026 return it as a sorted list. The list should be made by splicing together the nodes of the first two lists.\n        🐣: 1️⃣ Input: l1 = [1,2,4], l2 = [1,3,4] Output: [1,1,2,3,4,4] 2️⃣ Input: l1 = [], l2 = [] Output: [] 3️⃣ Input: l1 = [], l2 = [0] Output: [0]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution:  🐰\u0026🐢  Fast \u0026 Slow Pointers  ⏰: O(n) 🪐: O(1)\n\n            var mergeTwoLists = function (l1, l2) {\n              let dummy = new ListNode();\n              let curr = dummy;\n              while (l1 \u0026\u0026 l2) {\n                if (l1.val \u003c l2.val) {\n                  curr.next = l1;\n                  l1 = l1.next;\n                } else {\n                  curr.next = l2;\n                  l2 = l2.next;\n                }\n                curr = curr.next;\n              }\n              if (l1) curr.next = l1;\n              if (l2) curr.next = l2;\n              return dummy.next;\n            };\n  ## [Merge K Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/) #23\n\n        Pattern Used: K MERGE \n        ❓: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list \u0026 return it.\n        🐣: 1️⃣ Input: lists = [[1,4,5],[1,3,4],[2,6]] Output: [1,1,2,3,4,4,5,6] 2️⃣ Input: lists = [] Output: [] 3️⃣ Input: lists = [[]] Output: []\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution: Heap ⏰: O(n) 🪐: O(n)\n\n        import ListNode from \"DataStructures/LinkedList/ListNode.js\";\n        import MinHeap from \"DataStructures/Heaps/MinHeap.js\";\n\n            const mergeKLists = function (lists) {\n              if (lists.length === 0) return null;\n              let dummy = new ListNode();\n              let curr = dummy;\n              let minHeap = new MinHeap();\n              for (let i = 0; i \u003c lists.length; i++) {\n                if (lists[i]) minHeap.insert(lists[i]);\n              }\n              while (minHeap.size() \u003e 0) {\n                let node = minHeap.remove();\n                curr.next = node;\n                curr = curr.next;\n                if (node.next) minHeap.insert(node.next);\n              }\n              return dummy.next;\n            };\n## [Remove Nth Node From End Of List](https://leetcode.com/problems/remove-nth-node-from-end-of-list/) #19 🐰\u0026🐢\n        ❓: Given the head of a linked list, remove the nth node from the end of the list \u0026 return its head.\n        🐣: 1️⃣ Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] 2️⃣ Input: head = [1], n = 1 Output: [] 3️⃣ Input: head = [1,2], n = 1 Output: [1]\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution: 🐰\u0026🐢 Fast \u0026 Slow Pointers Fast \u0026 Slow Pointers  ⏰: O(n) 🪐: O(1)\n\n            var removeNthFromEnd = function (head, n) {\n              let dummy = new ListNode();\n              dummy.next = head;\n              let slow = dummy;\n              let fast = dummy;\n              for (let i = 0; i \u003c n; i++) {\n                fast = fast.next;\n              }\n              while (fast.next) {\n                slow = slow.next;\n                fast = fast.next;\n              }\n              slow.next = slow.next.next;\n              return dummy.next;\n            };\n## [Reorder List](https://leetcode.com/problems/reorder-list/) #143 🐰\u0026🐢\n        ❓: Given the head of a singly linked list, reorder the list to be: head -\u003e node 2 -\u003e node 3 -\u003e node 4 -\u003e ... -\u003e node n -\u003e null. You may not modify the values in the list's nodes. Only nodes themselves may be changed.\n        🐣: 1️⃣ Input: head = [1,2,3,4] Output: [1,4,2,3] 2️⃣ Input: head = [1,2,3,4,5] Output: [1,5,2,4,3]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution: 🐰\u0026🐢 Fast \u0026 Slow Pointers  ⏰: O(n) 🪐: O(1)\n\n            var reorderList = function (head) {\n              if (!head) return null;\n              let slow = head;\n              let fast = head;\n              while (fast \u0026\u0026 fast.next) {\n                slow = slow.next;\n                fast = fast.next.next;\n              }\n              let prev = null;\n              let curr = slow;\n              while (curr) {\n                let next = curr.next;\n                curr.next = prev;\n                prev = curr;\n                curr = next;\n              }\n              let first = head;\n              let second = prev;\n              while (second.next) {\n                let temp = first.next;\n                first.next = second;\n                first = temp;\n                temp = second.next;\n                second.next = first;\n                second = temp;\n              }\n            };\n---\n\n## Matrix\n\n## [Set Matrix Zeroes](https://leetcode.com/problems/set-matrix-zeroes/) #73  📐\n        ❓: Given an m x n matrix. If an element is 0, set its entire row \u0026 column to 0. Do it in-place.\n        🐣: 1️⃣ Input: matrix = [[1,1,1],[1,0,1],[1,1,1]] Output: [[1,0,1],[0,0,0],[1,0,1]] 2️⃣ Input: matrix = [[0,1,2,0],[3,4,5,2],[1,3,1,5]] Output: [[0,0,0,0],[0,4,5,0],[0,3,1,0]]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(mn) 🪐: O(m+n)\n        🐇 Solution:  📐 Matrix Pattern  ⏰: O(mn) 🪐: O(1)\n\n            var setZeroes = function (matrix) {\n              let rows = new Set();\n              let cols = new Set();\n              for (let i = 0; i \u003c matrix.length; i++) {\n                for (let j = 0; j \u003c matrix[0].length; j++) {\n                  if (matrix[i][j] === 0) {\n                    rows.add(i);\n                    cols.add(j);\n                  }\n                }\n              }\n              for (let i = 0; i \u003c matrix.length; i++) {\n                for (let j = 0; j \u003c matrix[0].length; j++) {\n                  if (rows.has(i) || cols.has(j)) {\n                    matrix[i][j] = 0;\n                  }\n                }\n              }\n            };\n\n## [Spiral Matrix](https://leetcode.com/problems/spiral-matrix/) #54  📐\n        Pattern Used:  📐 Matrix Pattern\n        ❓: Given an m x n matrix, return all elements of the matrix in spiral order.\n        🐣: 1️⃣ Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] 2️⃣ Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] Output: [1,2,3,4,8,12,11,10,9,5,6,7]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(mn) 🪐: O(mn)\n        🐇 Solution:   📐 Matrix Pattern  ⏰: O(mn) 🪐: O(mn)\n\n            var spiralOrder = function (matrix) {\n              let result = [];\n              let top = 0;\n              let bottom = matrix.length - 1;\n              let left = 0;\n              let right = matrix[0].length - 1;\n              while (top \u003c= bottom \u0026\u0026 left \u003c= right) {\n                for (let i = left; i \u003c= right; i++) {\n                  result.push(matrix[top][i]);\n                }\n                top++;\n                for (let i = top; i \u003c= bottom; i++) {\n                  result.push(matrix[i][right]);\n                }\n                right--;\n                if (top \u003c= bottom) {\n                  for (let i = right; i \u003e= left; i--) {\n                    result.push(matrix[bottom][i]);\n                  }\n                  bottom--;\n                }\n                if (left \u003c= right) {\n                  for (let i = bottom; i \u003e= top; i--) {\n                    result.push(matrix[i][left]);\n                  }\n                  left++;\n                }\n              }\n              return result;\n            };\n## [Rotate Image](https://leetcode.com/problems/rotate-image/) #48  📐\n        Pattern Used:  📐 Matrix Pattern\n        ❓: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise).\n        🐣: 1️⃣ Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [[7,4,1],[8,5,2],[9,6,3]] 2️⃣ Input: matrix = [[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]] Output: [[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]\n        \n        🐢 Solution: 🔨 Brute Force ⏰: 🔨 Brute Force ⏰:\n        🐇 Solution:  MatrixPattern ⏰: O(n) 🪐: O(1)\n\n            var rotate = function (matrix) {\n              let n = matrix.length;\n              for (let i = 0; i \u003c n / 2; i++) {\n                for (let j = i; j \u003c n - i - 1; j++) {\n                  let temp = matrix[i][j];\n                  matrix[i][j] = matrix[n - j - 1][i];\n                  matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1];\n                  matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1];\n                  matrix[j][n - i - 1] = temp;\n                }\n              }\n            };\n## [Word Search](https://leetcode.com/problems/word-search/) #79  📐\n        Pattern Used: Backtracking  📐 Matrix Pattern\n        ❓: Given an m x n grid of characters board \u0026 a string word, return true if word exists in the grid.\n        🐣: 1️⃣ Input: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\" Output: true 2️⃣ Input: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\" Output: true 3️⃣ Input: board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCB\" Output: false\n\n        🐢 Solution: 🔨 Brute Force ⏰ O(mn * 4^L) 🪐: O(mn)\n        🐇 Solution:  MatrixPattern ⏰: O(n) 🪐: O(n)\n\n            var exist = function (board, word) {\n              let m = board.length;\n              let n = board[0].length;\n              let visited = new Array(m);\n              for (let i = 0; i \u003c m; i++) {\n                visited[i] = new Array(n).fill(false);\n              }\n              let 🌲 DFS = (i, j, k) =\u003e {\n                if (i \u003c 0 || i \u003e= m || j \u003c 0 || j \u003e= n || visited[i][j] || board[i][j] !== word[k]) {\n                  return false;\n                }\n                if (k === word.length - 1) {\n                  return true;\n                }\n                visited[i][j] = true;\n                let result =\n                  🌲 DFS(i + 1, j, k + 1) ||\n                  🌲 DFS(i - 1, j, k + 1) ||\n                  🌲 DFS(i, j + 1, k + 1) ||\n                  🌲 DFS(i, j - 1, k + 1);\n                visited[i][j] = false;\n                return result;\n              };\n              for (let i = 0; i \u003c m; i++) {\n                for (let j = 0; j \u003c n; j++) {\n                  if (🌲 DFS(i, j, 0)) {\n                    return true;\n                  }\n                }\n              }\n              return false;\n            };\n\n---\n\n## String\n\n\n## [Valid Anagram](https://leetcode.com/problems/valid-anagram/) #242  \n        ❓: Given two strings s \u0026 t , write a function to determine if t is an anagram of s.\n        🐣: 1️⃣ Input: s = \"anagram\", t = \"nagaram\" Output: true 2️⃣ Input: s = \"rat\", t = \"car\" Output: false\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(nlogn) 🪐: O(n)\n        🐇 Solution:  Hash Table  ⏰: O(n) 🪐: O(n)\n \n            var isAnagram = function (s, t) {\n              if (s.length !== t.length) {\n                return false;\n              }\n              let map = new Map();\n              for (let i = 0; i \u003c s.length; i++) {\n                map.set(s[i], (map.get(s[i]) || 0) + 1);\n              }\n              for (let i = 0; i \u003c t.length; i++) {\n                if (!map.has(t[i])) {\n                  return false;\n                }\n                map.set(t[i], map.get(t[i]) - 1);\n                if (map.get(t[i]) \u003c 0) {\n                  return false;\n                }\n              }\n              return true;\n            };\n## [Group Anagrams](https://leetcode.com/problems/group-anagrams/) #49\n        ❓: Given an array of strings strs, group the anagrams together. You can return the answer in any order.\n        An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.\n        🐣: 1️⃣ Input: strs = [\"eat\",\"tea\",\"tan\",\"ate\",\"nat\",\"bat\"] Output: [[\"bat\"],[\"nat\",\"tan\"],[\"ate\",\"eat\",\"tea\"]] 2️⃣ Input: strs = [\"\"] Output: [[\"\"]] 3️⃣ Input: strs = [\"a\"] Output: [[\"a\"]]\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n^2)\n        🐇 Solution:  Hash Table  ⏰: O(n) 🪐: O(n)\n\n            var groupAnagrams = function (strs) {\n              let map = new Map();\n              for (let i = 0; i \u003c strs.length; i++) {\n                let sorted = strs[i].split(\"\").sort().join(\"\");\n                if (!map.has(sorted)) {\n                  map.set(sorted, []);\n                }\n                map.get(sorted).push(strs[i]);\n              }\n              return [...map.values()];\n            };\n## [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) #20\n        Pattern Used: Stack\n        ❓: Given a string s containing just the characters '(', ')', '{', '}', '[' \u0026 ']', determine if the input string is valid.\n        An input string is valid if:\n        Open brackets must be closed by the same type of brackets.\n        Open brackets must be closed in the correct order.\n        🐣: 1️⃣ Input: s = \"()\" Output: true 2️⃣ Input: s = \"()[]{}\" Output: true 3️⃣ Input: s = \"(]\" Output: false #4 Input: s = \"([)]\" Output: false #5 Input: s = \"{[]}\" Output: true\n        \n        🐢 Solution: 🔨 Brute Force ⏰: O(n^2) 🪐: O(n)\n        🐇 Solution: Stack  ⏰: O(n) 🪐: O(n)\n\n            var isValid = function (s) {\n              let stack = [];\n              let map = new Map();\n              map.set(\"(\", \")\");\n              map.set(\"{\", \"}\");\n              map.set(\"[\", \"]\");\n              for (let i = 0; i \u003c s.length; i++) {\n                if (map.has(s[i])) {\n                  stack.push(s[i]);\n                } else {\n                  if (map.get(stack.pop()) !== s[i]) {\n                    return false;\n                  }\n                }\n              }\n              return stack.length === 0;\n            };\n## [Valid Palindrome](https://leetcode.com/problems/valid-palindrome/) #125 👯\n        ❓: Given a string s, determine if it is a palindrome, considering only alphanumeric characters \u0026 ignoring cases.\n        🐣: 1️⃣ Input: s = \"A man, a plan, a canal: Panama\" Output: true Explain: \"amanaplanacanalpanama\" is a palindrome.\n        \n        🐢 Solution: 🔨 Brute Force ⏰: \n        🐇 Solution: 👯 Two Pointers ⏰: \n\n        var isPalindrome = function(s) {\n            let cursor1 = 0;\n            let cursor2 = s.length - 1;\n\n            while (cursor1 \u003c cursor2) {\n                if (!(/^[a-zA-Z0-9]*$/.test(s[cursor1]))) {\n                    cursor1++;\n                    continue;\n                }\n                if (!(/^[a-zA-Z0-9]*$/.test(s[cursor2]))) {\n                    cursor2--;\n                    continue;\n                }\n                if (s[cursor1].toLowerCase() === s[cursor2].toLowerCase()) {\n                    cursor1++;\n                    cursor2--;\n                    continue;\n                }\n                return false;\n            }\n\n            return true;\n        };\n            \n        }\n## [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/) #5 📈\n        ❓: Given a string s, return the longest palindromic substring in s.\n        🐣: 1️⃣ Input: s = \"babad\" Output: \"bab\" Note: \"aba\" is also a valid answer. 2️⃣ Input: s = \"cbbd\" Output: \"bb\" 3️⃣ Input: s = \"a\" Output: \"a\" #4 Input: s = \"ac\" Output: \"a\"\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n^3) 🪐: O(1)\n        🐇 Solution: 📈 Dynamic Programming ⏰: O(n^2) 🪐: O(n^2)\n\n            var longestPalindrome = function (s) {\n              let result = \"\";\n              for (let i = 0; i \u003c s.length; i++) {\n                let odd = exp\u0026(s, i, i);\n                let even = exp\u0026(s, i, i + 1);\n                let max = odd.length \u003e even.length ? odd : even;\n                if (max.length \u003e result.length) {\n                  result = max;\n                }\n              }\n              return result;\n            };\n            function exp\u0026(s, left, right) {\n              while (left \u003e= 0 \u0026\u0026 right \u003c s.length \u0026\u0026 s[left] === s[right]) {\n                left--;\n                right++;\n              }\n              return s.substring(left + 1, right);\n            }\n## [Palindromic Substrings](https://leetcode.com/problems/palindromic-substrings/) #647  📈 \n        ❓: Given a string s, return the number of palindromic substrings in it.\n        A string is a palindrome when it reads the same backward as forward.\n        A substring is a contiguous sequence of characters within the string.\n        🐣: 1️⃣ Input: s = \"abc\" Output: 3 Explain: Three palindromic strings: \"a\", \"b\", \"c\". 2️⃣ Input: s = \"aaa\" Output: 6 Explain: Six palindromic strings: \"a\", \"a\", \"a\", \"aa\", \"aa\", \"aaa\".\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n^3) 🪐: O(1)\n        🐇 Solution:  📈 Dynamic Programming ⏰: O(n^2) 🪐: O(n^2)\n\n            var countSubstrings = function (s) {\n              let count = 0;\n              for (let i = 0; i \u003c s.length; i++) {\n                count += exp\u0026(s, i, i);\n                count += exp\u0026(s, i, i + 1);\n              }\n              return count;\n            };\n            function exp\u0026(s, left, right) {\n              let count = 0;\n              while (left \u003e= 0 \u0026\u0026 right \u003c s.length \u0026\u0026 s[left] === s[right]) {\n                count++;\n                left--;\n                right++;\n              }\n              return count;\n            }\n\n---\n\n## Tree\n## [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/)🌲\n        ❓: Given the root of a binary tree, return its maximum depth.\n        A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.\n        🐣: 1️⃣ Input: root = [3,9,20,null,null,15,7] Output: 3 2️⃣ Input: root = [1,null,2] Output: 2 3️⃣ Input: root = [] Output: 0 #4 Input: root = [0] Output: 1\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution: 🌲 DFS ⏰: O(n) 🪐: O(n)\n\n            var maxDepth = function (root) {\n              if (!root) return 0;\n              return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;\n            };\n\n## [Same Tree](https://leetcode.com/problems/same-tree/) #100🌲\n        ❓: Given the roots of two binary trees p \u0026 q, write a function to check if they are the same or not.\n        Two binary trees are considered the same if they are structurally identical, \u0026 the nodes have the same value.\n        🐣: 1️⃣ Input: p = [1,2,3], q = [1,2,3] Output: true 2️⃣ Input: p = [1,2], q = [1,null,2] Output: false 3️⃣ Input: p = [1,2,1], q = [1,1,2] Output: false\n\n        🐢 Solution: 🔨 Brute Force ⏰: O(n) 🪐: O(n)\n        🐇 Solution: 🌲 DFS ⏰: O(n) 🪐: O(n)\n\n            var isSameTree = function (p, q) {\n              if (!p \u0026\u0026 !q) return true;\n              if (!p || !q) return false;\n              if (p.val !== q.val) return false;\n              return isSameTree(p.left, q.left) \u0026\u0026 isSameTree(p.right, q.right);\n            };\n\n## [Invert/Flip Binary Tree](https://leetcode.com/problems/invert-binary-tree/) #226🌲\n        ❓: Invert a binary tree.\n        🐣: 1️⃣ Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] 2️⃣ Input: root = [2,1,3] Outpu","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falishahusain%2Fnewt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falishahusain%2Fnewt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falishahusain%2Fnewt/lists"}