docs(docs): add ProblemBadges component, layout slot, and enrich pages with topics/video frontmatter, plus guide placeholders and topic‑landing map.

This commit is contained in:
Prad Nukala committed 2026-09-28 11:20:41 -04:00
1 parent b035d1ffa0
commit d2888360e2
104 files changed
+741 -355

No files matched your search

+7 -3
View File
@@ -1,7 +1,7 @@
/** /**
* Project MDX components, available on every page with no import. Static * Project MDX components, available on every page with no import, and layout
* `.astro` files ship no framework JS (a custom element carries any * slot overrides. Static `.astro` files ship no framework JS (a custom element
* behaviour); interactive React lives in `islands/` instead. * carries any behaviour); interactive React lives in `islands/` instead.
*/ */
import { defineComponents } from "blume"; import { defineComponents } from "blume";
@@ -10,4 +10,8 @@ export default defineComponents({
Carousel: "./components/Carousel.astro", Carousel: "./components/Carousel.astro",
CarouselImage: "./components/CarouselImage.astro", CarouselImage: "./components/CarouselImage.astro",
}, },
layout: {
// Problem pages' topic + explanation badges, from `topics:` / `video:` frontmatter.
PageHeader: "./components/ProblemBadges.astro",
},
}); });
+92
View File
@@ -0,0 +1,92 @@
---
/**
* The `PageHeader` slot: the badge row above a page's title. Blume hands the
* slot only the route, so the page's frontmatter is looked up through the
* route manifest — the same `getEntry` call Blume's own page template makes.
* Pages with none of the keys below (landing pages, the changelog) render
* nothing.
*
* - `topics:` (problem pages, written by `apps/cli/sync.ts`) is LeetCode's own
* topic tags. A tag the campaign teaches (`topic-landings.ts`) links to that
* topic's landing page and reads accent; any other tag links to its guide
* page, `/guides/<slug>` (sync creates one per such tag), and reads neutral.
* - `video:` (problem pages, written by `apps/cli/videos.ts`) is the NeetCode
* walkthrough's YouTube id, the red "Explanation" badge at the end of the row.
* - `list:` (guide pages, written by sync on create) is the tag's LeetCode
* problem list, an orange "LeetCode list" badge.
*
* A tag naming two campaign topics (`Depth-First Search` is both Tree DFS and
* Graph DFS) links to the page's own topic — its route's first segment — when
* that is one of them; otherwise DFS/BFS prefer the tree topic for a problem
* LeetCode also tags `Tree` and the graph topic for the rest. A route the site
* does not serve (a landing or guide page removed) falls back to LeetCode's
* problem list for the tag, so a badge never links to a 404.
*/
import { getEntry } from "astro:content";
import data from "blume:data";
import Badge from "blume/components/content/Badge.astro";
import { withBase } from "blume/components/islands/base-path.ts";
import { TOPIC_LANDINGS } from "../topic-landings.ts";
interface Props {
route: string;
}
interface TopicTag {
name: string;
slug: string;
}
const { route } = Astro.props;
const at = data.routes.find((r: { path: string }) => r.path === route);
const entry = at ? await getEntry(at.collection, at.entryId) : undefined;
const tags: TopicTag[] = entry?.data.topics ?? [];
const video: string | undefined = entry?.data.video;
const list: string | undefined = entry?.data.list;
const served = new Set(data.routes.map((r: { path: string }) => r.path));
const own = `/${route.split("/")[1]}`;
const prefer = tags.some((t) => t.slug === "tree") ? "/tree-" : "/graph-";
const badges = tags.map((tag) => {
const landings = (TOPIC_LANDINGS[tag.slug] ?? []).filter((path) => served.has(path));
const landing = landings.includes(own) ? own : (landings.find((p) => p.startsWith(prefer)) ?? landings[0]);
if (landing) return { name: tag.name, href: withBase(landing), accent: true, external: false };
const guide = `/guides/${tag.slug}`;
if (served.has(guide)) return { name: tag.name, href: withBase(guide), accent: false, external: false };
return { name: tag.name, href: `https://leetcode.com/problem-list/${tag.slug}/`, accent: false, external: true };
});
const linkClass = "no-underline transition-opacity hover:opacity-80";
---
{
(badges.length > 0 || video || list) && (
<div class="not-prose mx-auto mb-4 flex max-w-content flex-wrap gap-1.5">
{badges.map((b) => (
<a
href={b.href}
target={b.external ? "_blank" : undefined}
rel={b.external ? "noopener" : undefined}
class={linkClass}
>
<Badge variant={b.accent ? "accent" : "default"}>{b.name}</Badge>
</a>
))}
{video && (
<a href={`https://www.youtube.com/watch?v=${video}`} target="_blank" rel="noopener" class={linkClass}>
<Badge variant="danger" icon="youtube">
Explanation
</Badge>
</a>
)}
{list && (
<a href={list} target="_blank" rel="noopener" class={linkClass}>
<Badge variant="warning" icon="list">
LeetCode list
</Badge>
</a>
)}
</div>
)
}
@@ -2,13 +2,15 @@
title: '153. Find Minimum in Rotated Sorted Array' title: '153. Find Minimum in Rotated Sorted Array'
description: 'Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:' description: 'Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:'
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
video: "nIVW4P8b1VA"
sidebar: sidebar:
label: 'Find Minimum in Rotated Sorted Array' label: 'Find Minimum in Rotated Sorted Array'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
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]]. 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]].
:::: ::::
@@ -69,7 +71,3 @@ class Solution:
return nums[lowest_index] return nums[lowest_index]
``` ```
## Explanation
<YouTube id="nIVW4P8b1VA" title="Find Minimum in Rotated Sorted Array - Binary Search - Leetcode 153 - Python" />
@@ -2,13 +2,15 @@
title: '33. Search in Rotated Sorted Array' title: '33. Search in Rotated Sorted Array'
description: There is an integer array nums sorted in ascending order (with distinct values) description: There is an integer array nums sorted in ascending order (with distinct values)
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
video: "U8XENwh8Oy8"
sidebar: sidebar:
label: 'Search in Rotated Sorted Array' label: 'Search in Rotated Sorted Array'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must write an algorithm with O(log n) runtime complexity. You must write an algorithm with O(log n) runtime complexity.
:::: ::::
@@ -93,7 +95,3 @@ var search = function(nums, target) {
return -1; return -1;
}; };
``` ```
## Explanation
<YouTube id="U8XENwh8Oy8" title="Search in rotated sorted array - Leetcode 33 - Python" />
@@ -2,13 +2,15 @@
title: '35. Search Insert Position' title: '35. Search Insert Position'
description: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order description: Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
video: "K-RYzDZkzCI"
sidebar: sidebar:
label: 'Search Insert Position' label: 'Search Insert Position'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must write an algorithm with O(log n) runtime complexity. You must write an algorithm with O(log n) runtime complexity.
:::: ::::
@@ -66,7 +68,3 @@ class Solution:
return (l + r) // 2 + 1 return (l + r) // 2 + 1
``` ```
## Explanation
<YouTube id="K-RYzDZkzCI" title="Search Insert Position - Binary Search - Leetcode 35 - Python" />
@@ -2,13 +2,15 @@
title: '704. Binary Search' title: '704. Binary Search'
description: Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1 description: Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
video: "s4DPM8ct1pI"
sidebar: sidebar:
label: 'Binary Search' label: 'Binary Search'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must write an algorithm with O(log n) runtime complexity. You must write an algorithm with O(log n) runtime complexity.
:::: ::::
@@ -71,7 +73,3 @@ var search = function(nums, target) {
return -1; return -1;
}; };
``` ```
## Explanation
<YouTube id="s4DPM8ct1pI" title="Binary Search - Leetcode 704 - Python" />
@@ -2,13 +2,16 @@
title: '74. Search a 2D Matrix' title: '74. Search a 2D Matrix'
description: 'You are given an m x n integer matrix matrix with the following two properties:' description: 'You are given an m x n integer matrix matrix with the following two properties:'
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
- { name: "Matrix", slug: "matrix" }
video: "Ber2pi2C0j0"
sidebar: sidebar:
label: 'Search a 2D Matrix' label: 'Search a 2D Matrix'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must write a solution in O(log(m * n)) time complexity. You must write a solution in O(log(m * n)) time complexity.
:::: ::::
@@ -86,7 +89,3 @@ class Solution:
return True return True
return False return False
``` ```
## Explanation
<YouTube id="Ber2pi2C0j0" title="Search a 2D Matrix - Leetcode 74 - Python" />
@@ -2,13 +2,15 @@
title: '875. Koko Eating Bananas' title: '875. Koko Eating Bananas'
description: Koko loves to eat bananas. There are n piles of bananas, the i^th pile has piles[i] bananas. The guards have gone and will come back in h hours description: Koko loves to eat bananas. There are n piles of bananas, the i^th pile has piles[i] bananas. The guards have gone and will come back in h hours
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Binary Search", slug: "binary-search" }
video: "U2SozAs9RzA"
sidebar: sidebar:
label: 'Koko Eating Bananas' label: 'Koko Eating Bananas'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `piles = [3,6,7,11], h = 8` - Input: `piles = [3,6,7,11], h = 8`
- Output: `4` - Output: `4`
@@ -77,7 +79,3 @@ var minEatingSpeed = function(piles, h) {
return l; return l;
}; };
``` ```
## Explanation
<YouTube id="U2SozAs9RzA" title="Koko Eating Bananas - Binary Search - Leetcode 875 - Python" />
@@ -2,13 +2,15 @@
title: '1. Two Sum' title: '1. Two Sum'
description: You are given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target description: You are given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
video: "KLlXCFG5TnA"
sidebar: sidebar:
label: 'Two Sum' label: 'Two Sum'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Can you come up with an algorithm that is less than O(n^2) time complexity? Can you come up with an algorithm that is less than O(n^2) time complexity?
:::: ::::
@@ -60,7 +62,3 @@ class Solution:
seen[num] = i seen[num] = i
return [] return []
``` ```
## Explanation
<YouTube id="KLlXCFG5TnA" title="Two Sum - Leetcode 1 - HashMap - Python" />
@@ -2,13 +2,14 @@
title: '1832. Check if the Sentence Is Pangram' title: '1832. Check if the Sentence Is Pangram'
description: A pangram is a sentence where every letter of the English alphabet appears at least once description: A pangram is a sentence where every letter of the English alphabet appears at least once
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
sidebar: sidebar:
label: 'Check if the Sentence Is Pangram' label: 'Check if the Sentence Is Pangram'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `sentence = "thequickbrownfoxjumpsoverthelazydog"` - Input: `sentence = "thequickbrownfoxjumpsoverthelazydog"`
- Output: `true` - Output: `true`
@@ -2,13 +2,16 @@
title: '217. Contains Duplicate' title: '217. Contains Duplicate'
description: Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct description: Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
- { name: "Sorting", slug: "sorting" }
video: "3OamzN90kPg"
sidebar: sidebar:
label: 'Contains Duplicate' label: 'Contains Duplicate'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [1,2,3,1]` - Input: `nums = [1,2,3,1]`
- Output: `true` - Output: `true`
@@ -48,7 +51,3 @@ class Solution:
def containsDuplicate(self, nums: List[int]) -> bool: def containsDuplicate(self, nums: List[int]) -> bool:
return len(set(nums)) != len(nums) return len(set(nums)) != len(nums)
``` ```
## Explanation
<YouTube id="3OamzN90kPg" title="Contains Duplicate - Leetcode 217 - Python" />
@@ -2,13 +2,16 @@
title: '242. Valid Anagram' title: '242. Valid Anagram'
description: Given two strings s and t, return true if t is an anagram of s, and false otherwise description: Given two strings s and t, return true if t is an anagram of s, and false otherwise
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Sorting", slug: "sorting" }
video: "9UtInBqnCgA"
sidebar: sidebar:
label: 'Valid Anagram' label: 'Valid Anagram'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Hash Table</Badge>
::::warning ::::warning
What if the inputs contain Unicode characters? How would you adapt your solution to such a case? What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
:::: ::::
@@ -60,7 +63,3 @@ var isAnagram = function(s, t) {
return true; return true;
}; };
``` ```
## Explanation
<YouTube id="9UtInBqnCgA" title="Valid Anagram - Leetcode 242 - Python" />
@@ -2,13 +2,21 @@
title: '347. Top K Frequent Elements' title: '347. Top K Frequent Elements'
description: Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order description: Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
- { name: "Divide and Conquer", slug: "divide-and-conquer" }
- { name: "Sorting", slug: "sorting" }
- { name: "Heap (Priority Queue)", slug: "heap-priority-queue" }
- { name: "Bucket Sort", slug: "bucket-sort" }
- { name: "Counting", slug: "counting" }
- { name: "Quickselect", slug: "quickselect" }
video: "YPTqKIgVk-k"
sidebar: sidebar:
label: 'Top K Frequent Elements' label: 'Top K Frequent Elements'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Your algorithm's time complexity must be better than O(n log n), where n is the array's size. Your algorithm's time complexity must be better than O(n log n), where n is the array's size.
:::: ::::
@@ -60,7 +68,3 @@ var topKFrequent = function (nums, k) {
.slice(0, k); .slice(0, k);
}; };
``` ```
## Explanation
<YouTube id="YPTqKIgVk-k" title="Top K Frequent Elements - Bucket Sort - Leetcode 347 - Python" />
@@ -2,13 +2,17 @@
title: '387. First Unique Character in a String' title: '387. First Unique Character in a String'
description: Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1 description: Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Queue", slug: "queue" }
- { name: "Counting", slug: "counting" }
video: "rBENYgWy3xU"
sidebar: sidebar:
label: 'First Unique Character in a String' label: 'First Unique Character in a String'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `s = "leetcode"` - Input: `s = "leetcode"`
- Output: `0` - Output: `0`
@@ -58,7 +62,3 @@ var firstUniqChar = function (s) {
return -1; return -1;
}; };
``` ```
## Explanation
<YouTube id="rBENYgWy3xU" title="First Unique Character in a String - Leetcode 387 - Python" />
@@ -2,13 +2,19 @@
title: '451. Sort Characters By Frequency' title: '451. Sort Characters By Frequency'
description: Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string description: Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Sorting", slug: "sorting" }
- { name: "Heap (Priority Queue)", slug: "heap-priority-queue" }
- { name: "Bucket Sort", slug: "bucket-sort" }
- { name: "Counting", slug: "counting" }
video: "OXdXc9HTrIg"
sidebar: sidebar:
label: 'Sort Characters By Frequency' label: 'Sort Characters By Frequency'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `s = "tree"` - Input: `s = "tree"`
- Output: `"eert"` - Output: `"eert"`
@@ -60,7 +66,3 @@ var frequencySort = function (s) {
.join(""); .join("");
}; };
``` ```
## Explanation
<YouTube id="OXdXc9HTrIg" title="Sort Characters By Frequency - Leetcode 451 - Python" />
@@ -2,13 +2,17 @@
title: '49. Group Anagrams' title: '49. Group Anagrams'
description: Given an array of strings strs, group the anagrams together. You can return the answer in any order description: Given an array of strings strs, group the anagrams together. You can return the answer in any order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Sorting", slug: "sorting" }
video: "vzdNOK2oB2E"
sidebar: sidebar:
label: 'Group Anagrams' label: 'Group Anagrams'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `strs = ["eat","tea","tan","ate","nat","bat"]` - Input: `strs = ["eat","tea","tan","ate","nat","bat"]`
- Output: `[["bat"],["nat","tan"],["ate","eat","tea"]]` - Output: `[["bat"],["nat","tan"],["ate","eat","tea"]]`
@@ -65,7 +69,3 @@ var groupAnagrams = function(strs) {
return Object.values(anagrams); return Object.values(anagrams);
}; };
``` ```
## Explanation
<YouTube id="vzdNOK2oB2E" title="Group Anagrams - Categorize Strings by Count - Leetcode 49" />
@@ -2,13 +2,16 @@
title: '739. Daily Temperatures' title: '739. Daily Temperatures'
description: Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the i^th day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead description: Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the i^th day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Stack", slug: "stack" }
- { name: "Monotonic Stack", slug: "monotonic-stack" }
video: "cTBiBSnjO3c"
sidebar: sidebar:
label: 'Daily Temperatures' label: 'Daily Temperatures'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `temperatures = [73,74,75,71,69,72,76,73]` - Input: `temperatures = [73,74,75,71,69,72,76,73]`
- Output: `[1,1,4,2,1,1,0,0]` - Output: `[1,1,4,2,1,1,0,0]`
@@ -54,7 +57,3 @@ class Solution:
stack.append(i) stack.append(i)
return ans return ans
``` ```
## Explanation
<YouTube id="cTBiBSnjO3c" title="Daily Temperatures - Monotonic Stack - Leetcode 739 - Python" />
@@ -2,13 +2,17 @@
title: '853. Car Fleet' title: '853. Car Fleet'
description: There are n cars at given miles away from the starting mile 0, traveling to reach the mile target description: There are n cars at given miles away from the starting mile 0, traveling to reach the mile target
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Stack", slug: "stack" }
- { name: "Sorting", slug: "sorting" }
- { name: "Monotonic Stack", slug: "monotonic-stack" }
video: "Pr6T-3yB9RM"
sidebar: sidebar:
label: 'Car Fleet' label: 'Car Fleet'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]` - Input: `target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3]`
- Output: `3` - Output: `3`
@@ -62,7 +66,3 @@ class Solution:
return len(stack) return len(stack)
``` ```
## Explanation
<YouTube id="Pr6T-3yB9RM" title="Car Fleet - Leetcode 853 - Python" />
@@ -2,13 +2,15 @@
title: '238. Product of Array Except Self' title: '238. Product of Array Except Self'
description: 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] description: 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]
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Prefix Sum", slug: "prefix-sum" }
video: "bNvIQI2wAjk"
sidebar: sidebar:
label: 'Product of Array Except Self' label: 'Product of Array Except Self'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must write an algorithm that runs in O(n) time and without using the division operation. You must write an algorithm that runs in O(n) time and without using the division operation.
Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.) Can you solve the problem in O(1) extra space complexity? (The output array does not count as extra space for space complexity analysis.)
@@ -63,7 +65,3 @@ var productExceptSelf = function(nums) {
return answer; return answer;
}; };
``` ```
## Explanation
<YouTube id="bNvIQI2wAjk" title="Product of Array Except Self - Leetcode 238 - Python" />
@@ -2,13 +2,16 @@
title: '303. Range Sum Query - Immutable' title: '303. Range Sum Query - Immutable'
description: Given an integer array nums, handle multiple queries of the following type description: Given an integer array nums, handle multiple queries of the following type
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Design", slug: "design" }
- { name: "Prefix Sum", slug: "prefix-sum" }
video: "2pndAmo_sMA"
sidebar: sidebar:
label: 'Range Sum Query - Immutable' label: 'Range Sum Query - Immutable'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `["NumArray", "sumRange", "sumRange", "sumRange"]` `[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]` - Input: `["NumArray", "sumRange", "sumRange", "sumRange"]` `[[[-2, 0, 3, -5, 2, -1]], [0, 2], [2, 5], [0, 5]]`
- Output: `[null, 1, -1, -3]` - Output: `[null, 1, -1, -3]`
@@ -66,7 +69,3 @@ class NumArray {
* var param_1 = obj.sumRange(left,right) * var param_1 = obj.sumRange(left,right)
*/ */
``` ```
## Explanation
<YouTube id="2pndAmo_sMA" title="Range Sum Query Immutable - Leetcode 303 - Python" />
@@ -2,13 +2,16 @@
title: '560. Subarray Sum Equals K' title: '560. Subarray Sum Equals K'
description: Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k description: Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
- { name: "Prefix Sum", slug: "prefix-sum" }
video: "fFVZt-6sgyo"
sidebar: sidebar:
label: 'Subarray Sum Equals K' label: 'Subarray Sum Equals K'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [1,1,1], k = 2` - Input: `nums = [1,1,1], k = 2`
- Output: `2` - Output: `2`
@@ -65,7 +68,3 @@ var subarraySum = function(nums, k) {
return count return count
}; };
``` ```
## Explanation
<YouTube id="fFVZt-6sgyo" title="Subarray Sum Equals K - Prefix Sums - Leetcode 560 - Python" />
@@ -2,13 +2,15 @@
title: '121. Best Time to Buy and Sell Stock' title: '121. Best Time to Buy and Sell Stock'
description: You are given an array prices where prices[i] is the price of a given stock on the i^th day description: You are given an array prices where prices[i] is the price of a given stock on the i^th day
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Dynamic Programming", slug: "dynamic-programming" }
video: "1pkOgXD63yU"
sidebar: sidebar:
label: 'Best Time to Buy and Sell Stock' label: 'Best Time to Buy and Sell Stock'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `prices = [7,1,5,3,6,4]` - Input: `prices = [7,1,5,3,6,4]`
- Output: `5` - Output: `5`
@@ -55,7 +57,3 @@ class Solution:
ans = max(ans, curr) ans = max(ans, curr)
return ans return ans
``` ```
## Explanation
<YouTube id="1pkOgXD63yU" title="Sliding Window: Best Time to Buy and Sell Stock - Leetcode 121 - Python" />
@@ -2,13 +2,16 @@
title: '3. Longest Substring Without Repeating Characters' title: '3. Longest Substring Without Repeating Characters'
description: Given a string s, find the length of the longest substring without duplicate characters description: Given a string s, find the length of the longest substring without duplicate characters
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Sliding Window", slug: "sliding-window" }
video: "wiGpQwVHdE0"
sidebar: sidebar:
label: 'Longest Substring Without Repeating Characters' label: 'Longest Substring Without Repeating Characters'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `s = "abcabcbb"` - Input: `s = "abcabcbb"`
- Output: `3` - Output: `3`
@@ -61,7 +64,3 @@ class Solution:
return ans return ans
``` ```
## Explanation
<YouTube id="wiGpQwVHdE0" title="Longest Substring Without Repeating Characters - Leetcode 3 - Python" />
@@ -2,13 +2,16 @@
title: '424. Longest Repeating Character Replacement' title: '424. Longest Repeating Character Replacement'
description: You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times description: You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Sliding Window", slug: "sliding-window" }
video: "gqXU1UyA8pk"
sidebar: sidebar:
label: 'Longest Repeating Character Replacement' label: 'Longest Repeating Character Replacement'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `s = "ABAB", k = 2` - Input: `s = "ABAB", k = 2`
- Output: `4` - Output: `4`
@@ -61,7 +64,3 @@ class Solution:
res = max(res, r - l + 1) res = max(res, r - l + 1)
return res return res
``` ```
## Explanation
<YouTube id="gqXU1UyA8pk" title="Longest Repeating Character Replacement - Leetcode 424 - Python" />
@@ -2,13 +2,17 @@
title: '567. Permutation in String' title: '567. Permutation in String'
description: Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise description: Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "String", slug: "string" }
- { name: "Sliding Window", slug: "sliding-window" }
video: "UbyhOgBN834"
sidebar: sidebar:
label: 'Permutation in String' label: 'Permutation in String'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `s1 = "ab", s2 = "eidbaooo"` - Input: `s1 = "ab", s2 = "eidbaooo"`
- Output: `true` - Output: `true`
@@ -68,7 +72,3 @@ class Solution:
return False return False
``` ```
## Explanation
<YouTube id="UbyhOgBN834" title="Permutation in String - Leetcode 567 - Python" />
@@ -2,13 +2,16 @@
title: '150. Evaluate Reverse Polish Notation' title: '150. Evaluate Reverse Polish Notation'
description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation description: You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Math", slug: "math" }
- { name: "Stack", slug: "stack" }
video: "iu0082c4HDE"
sidebar: sidebar:
label: 'Evaluate Reverse Polish Notation' label: 'Evaluate Reverse Polish Notation'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `tokens = ["2","1","+","3","*"]` - Input: `tokens = ["2","1","+","3","*"]`
- Output: `9` - Output: `9`
@@ -69,7 +72,3 @@ class Solution:
return stack[0] return stack[0]
``` ```
## Explanation
<YouTube id="iu0082c4HDE" title="Evaluate Reverse Polish Notation - Leetcode 150 - Python" />
@@ -2,13 +2,15 @@
title: '155. Min Stack' title: '155. Min Stack'
description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time description: Design a stack that supports push, pop, top, and retrieving the minimum element in constant time
icon: dot icon: dot
topics:
- { name: "Stack", slug: "stack" }
- { name: "Design", slug: "design" }
video: "qkLl7nAwDPo"
sidebar: sidebar:
label: 'Min Stack' label: 'Min Stack'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Stack</Badge>
::::warning ::::warning
You must implement a solution with O(1) time complexity for each function. You must implement a solution with O(1) time complexity for each function.
:::: ::::
@@ -77,7 +79,3 @@ class MinStack:
# param_3 = obj.top() # param_3 = obj.top()
# param_4 = obj.getMin() # param_4 = obj.getMin()
``` ```
## Explanation
<YouTube id="qkLl7nAwDPo" title="Design Min Stack - Amazon Interview Question - Leetcode 155 - Python" />
@@ -2,13 +2,16 @@
title: '20. Valid Parentheses' title: '20. Valid Parentheses'
description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid description: Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid
icon: dot icon: dot
topics:
- { name: "String", slug: "string" }
- { name: "Stack", slug: "stack" }
- { name: "Bracket Sequences", slug: "bracket-sequences" }
video: "WTzjTskDFMg"
sidebar: sidebar:
label: 'Valid Parentheses' label: 'Valid Parentheses'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">String</Badge>
### Example 1: ### Example 1:
- Input: `s = "()"` - Input: `s = "()"`
- Output: `true` - Output: `true`
@@ -71,7 +74,3 @@ class Solution:
return True if not stack else False return True if not stack else False
``` ```
## Explanation
<YouTube id="WTzjTskDFMg" title="Valid Parentheses - Stack - Leetcode 20 - Python" />
@@ -2,13 +2,16 @@
title: '11. Container With Most Water' title: '11. Container With Most Water'
description: You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the i^th line are (i, 0) and (i, height[i]) description: You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the i^th line are (i, 0) and (i, height[i])
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "Greedy", slug: "greedy" }
video: "UuiTKBwPgAo"
sidebar: sidebar:
label: 'Container With Most Water' label: 'Container With Most Water'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Notice that you may not slant the container. Notice that you may not slant the container.
:::: ::::
@@ -63,7 +66,3 @@ class Solution:
return res return res
``` ```
## Explanation
<YouTube id="UuiTKBwPgAo" title="Container with Most Water - Leetcode 11 - Python" />
@@ -2,13 +2,15 @@
title: '125. Valid Palindrome' title: '125. Valid Palindrome'
description: A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers description: A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the same forward and backward. Alphanumeric characters include letters and numbers
icon: dot icon: dot
topics:
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "String", slug: "string" }
video: "jJXJ16kPFWg"
sidebar: sidebar:
label: 'Valid Palindrome' label: 'Valid Palindrome'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Two Pointers</Badge>
### Example 1: ### Example 1:
- Input: `s = "A man, a plan, a canal: Panama"` - Input: `s = "A man, a plan, a canal: Panama"`
- Output: `true` - Output: `true`
@@ -64,7 +66,3 @@ var isPalindrome = function(s) {
return true; return true;
}; };
``` ```
## Explanation
<YouTube id="jJXJ16kPFWg" title="Valid Palindrome - Leetcode 125 - Python" />
@@ -2,13 +2,16 @@
title: '15. 3Sum' title: '15. 3Sum'
description: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0 description: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "Sorting", slug: "sorting" }
video: "jzZsG8n2R9A"
sidebar: sidebar:
label: '3Sum' label: '3Sum'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Notice that the solution set must not contain duplicate triplets. Notice that the solution set must not contain duplicate triplets.
:::: ::::
@@ -99,7 +102,3 @@ class Solution:
return result return result
``` ```
## Explanation
<YouTube id="jzZsG8n2R9A" title="3Sum - Leetcode 15 - Python" />
@@ -2,13 +2,16 @@
title: '167. Two Sum II - Input Array Is Sorted' title: '167. Two Sum II - Input Array Is Sorted'
description: Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length description: Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "Binary Search", slug: "binary-search" }
video: "cQ1Oz4ckceM"
sidebar: sidebar:
label: 'Two Sum II - Input Array Is Sorted' label: 'Two Sum II - Input Array Is Sorted'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Your solution must use only constant extra space. Your solution must use only constant extra space.
:::: ::::
@@ -70,7 +73,3 @@ class Solution:
j-=1 j-=1
return [] return []
``` ```
## Explanation
<YouTube id="cQ1Oz4ckceM" title="TWO SUM II - Amazon Coding Interview Question - Leetcode 167 - Python" />
@@ -2,13 +2,15 @@
title: '344. Reverse String' title: '344. Reverse String'
description: Write a function that reverses a string. The input string is given as an array of characters s description: Write a function that reverses a string. The input string is given as an array of characters s
icon: dot icon: dot
topics:
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "String", slug: "string" }
video: "_d0T_2Lk2qA"
sidebar: sidebar:
label: 'Reverse String' label: 'Reverse String'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Two Pointers</Badge>
:::warning :::warning
You must do this by modifying the input array in-place with O(1) extra memory. You must do this by modifying the input array in-place with O(1) extra memory.
::: :::
@@ -56,7 +58,3 @@ var reverseString = function(s) {
} }
}; };
``` ```
## Explanation
<YouTube id="_d0T_2Lk2qA" title="Reverse String - 3 Ways - Leetcode 344 - Python" />
@@ -2,13 +2,16 @@
title: '392. Is Subsequence' title: '392. Is Subsequence'
description: Given two strings s and t, return true if s is a subsequence of t, or false otherwise description: Given two strings s and t, return true if s is a subsequence of t, or false otherwise
icon: dot icon: dot
topics:
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "String", slug: "string" }
- { name: "Dynamic Programming", slug: "dynamic-programming" }
video: "99RVfqklbCE"
sidebar: sidebar:
label: 'Is Subsequence' label: 'Is Subsequence'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Two Pointers</Badge>
::::warning ::::warning
Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 10^9, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code? Suppose there are lots of incoming s, say s1, s2, ..., sk where k >= 10^9, and you want to check one by one to see if t has its subsequence. In this scenario, how would you change your code?
:::: ::::
@@ -59,7 +62,3 @@ class Solution:
return i == len(s) return i == len(s)
``` ```
## Explanation
<YouTube id="99RVfqklbCE" title="Is Subsequence - Leetcode 392" />
@@ -2,13 +2,16 @@
title: '977. Squares of a Sorted Array' title: '977. Squares of a Sorted Array'
description: Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order description: Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "Sorting", slug: "sorting" }
video: "FPCZsG_AkUg"
sidebar: sidebar:
label: 'Squares of a Sorted Array' label: 'Squares of a Sorted Array'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach? Squaring each element and sorting the new array is very trivial, could you find an O(n) solution using a different approach?
:::: ::::
@@ -69,7 +72,3 @@ var sortedSquares = function(nums) {
return ans; return ans;
}; };
``` ```
## Explanation
<YouTube id="FPCZsG_AkUg" title="Squares of a Sorted Array - Leetcode 977 - Python" />
@@ -2,13 +2,17 @@
title: '146. LRU Cache' title: '146. LRU Cache'
description: Design a data structure that follows the constraints of a Least Recently Used (LRU) cache description: Design a data structure that follows the constraints of a Least Recently Used (LRU) cache
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "Linked List", slug: "linked-list" }
- { name: "Design", slug: "design" }
- { name: "Doubly-Linked List", slug: "doubly-linked-list" }
video: "7ABFKPK2hD4"
sidebar: sidebar:
label: 'LRU Cache' label: 'LRU Cache'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `` - Input: ``
- Output: `` - Output: ``
@@ -110,7 +114,3 @@ class LRUCache:
# param_1 = obj.get(key) # param_1 = obj.get(key)
# obj.put(key,value) # obj.put(key,value)
``` ```
## Explanation
<YouTube id="7ABFKPK2hD4" title="LRU Cache - Twitch Interview Question - Leetcode 146" />
@@ -2,13 +2,16 @@
title: '2. Add Two Numbers' title: '2. Add Two Numbers'
description: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list description: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list
icon: dot icon: dot
topics:
- { name: "Linked List", slug: "linked-list" }
- { name: "Math", slug: "math" }
- { name: "Recursion", slug: "recursion" }
video: "wgFPrzTjm7s"
sidebar: sidebar:
label: 'Add Two Numbers' label: 'Add Two Numbers'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Linked List</Badge>
### Example 1: ### Example 1:
- Input: `l1 = [2,4,3], l2 = [5,6,4]` - Input: `l1 = [2,4,3], l2 = [5,6,4]`
- Output: `[7,0,8]` - Output: `[7,0,8]`
@@ -70,7 +73,3 @@ class Solution:
return dummy.next return dummy.next
``` ```
## Explanation
<YouTube id="wgFPrzTjm7s" title="Add Two Numbers - Leetcode 2 - Python" />
@@ -2,13 +2,17 @@
title: '141. Linked List Cycle' title: '141. Linked List Cycle'
description: Given head, the head of a linked list, determine if the linked list has a cycle in it description: Given head, the head of a linked list, determine if the linked list has a cycle in it
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "Linked List", slug: "linked-list" }
- { name: "Two Pointers", slug: "two-pointers" }
- { name: "Floyd's Cycle Finding Algorithm", slug: "floyds-cycle-finding-algorithm" }
video: "gBTe7lFR3vc"
sidebar: sidebar:
label: 'Linked List Cycle' label: 'Linked List Cycle'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Hash Table</Badge>
::::warning ::::warning
Can you solve it using O(1) (i.e. constant) memory? Can you solve it using O(1) (i.e. constant) memory?
:::: ::::
@@ -69,7 +73,3 @@ class Solution:
return True return True
return False return False
``` ```
## Explanation
<YouTube id="gBTe7lFR3vc" title="Linked List Cycle - Floyd's Tortoise and Hare - Leetcode 141 - Python" />
@@ -2,13 +2,15 @@
title: '206. Reverse Linked List' title: '206. Reverse Linked List'
description: Given the head of a singly linked list, reverse the list, and return the reversed list description: Given the head of a singly linked list, reverse the list, and return the reversed list
icon: dot icon: dot
topics:
- { name: "Linked List", slug: "linked-list" }
- { name: "Recursion", slug: "recursion" }
video: "G0_I-ZF0S38"
sidebar: sidebar:
label: 'Reverse Linked List' label: 'Reverse Linked List'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Linked List</Badge>
::::warning ::::warning
A linked list can be reversed either iteratively or recursively. Could you implement both? A linked list can be reversed either iteratively or recursively. Could you implement both?
:::: ::::
@@ -62,7 +64,3 @@ class Solution:
curr = next_ curr = next_
return prev return prev
``` ```
## Explanation
<YouTube id="G0_I-ZF0S38" title="Reverse Linked List - Iterative AND Recursive - Leetcode 206 - Python" />
@@ -2,13 +2,15 @@
title: '21. Merge Two Sorted Lists' title: '21. Merge Two Sorted Lists'
description: You are given the heads of two sorted linked lists list1 and list2 description: You are given the heads of two sorted linked lists list1 and list2
icon: dot icon: dot
topics:
- { name: "Linked List", slug: "linked-list" }
- { name: "Recursion", slug: "recursion" }
video: "XIdigk956u0"
sidebar: sidebar:
label: 'Merge Two Sorted Lists' label: 'Merge Two Sorted Lists'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Linked List</Badge>
### Example 1: ### Example 1:
- Input: `list1 = [1,2,4], list2 = [1,3,4]` - Input: `list1 = [1,2,4], list2 = [1,3,4]`
- Output: `[1,1,2,3,4,4]` - Output: `[1,1,2,3,4,4]`
@@ -82,7 +84,3 @@ class Solution:
current.next = list1 or list2 current.next = list1 or list2
return head return head
``` ```
## Explanation
<YouTube id="XIdigk956u0" title="Merge Two Sorted Lists - Leetcode 21 - Python" />
@@ -2,13 +2,16 @@
title: '48. Rotate Image' title: '48. Rotate Image'
description: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) description: You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise)
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Math", slug: "math" }
- { name: "Matrix", slug: "matrix" }
video: "fMSJSS7eO1w"
sidebar: sidebar:
label: 'Rotate Image' label: 'Rotate Image'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]` - Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]`
- Output: `[[7,4,1],[8,5,2],[9,6,3]]` - Output: `[[7,4,1],[8,5,2],[9,6,3]]`
@@ -52,7 +55,3 @@ class Solution:
for r in range(n): for r in range(n):
matrix[r].reverse() matrix[r].reverse()
``` ```
## Explanation
<YouTube id="fMSJSS7eO1w" title="Rotate Image - Matrix - Leetcode 48" />
@@ -2,13 +2,16 @@
title: '54. Spiral Matrix' title: '54. Spiral Matrix'
description: Given an m x n matrix, return all elements of the matrix in spiral order description: Given an m x n matrix, return all elements of the matrix in spiral order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Matrix", slug: "matrix" }
- { name: "Simulation", slug: "simulation" }
video: "BJnMZNwUk1M"
sidebar: sidebar:
label: 'Spiral Matrix' label: 'Spiral Matrix'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]` - Input: `matrix = [[1,2,3],[4,5,6],[7,8,9]]`
- Output: `[1,2,3,6,9,8,7,4,5]` - Output: `[1,2,3,6,9,8,7,4,5]`
@@ -76,7 +79,3 @@ class Solution:
return res return res
``` ```
## Explanation
<YouTube id="BJnMZNwUk1M" title="Spiral Matrix - Microsoft Interview Question - Leetcode 54" />
@@ -2,13 +2,16 @@
title: '73. Set Matrix Zeroes' title: '73. Set Matrix Zeroes'
description: Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's description: Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Hash Table", slug: "hash-table" }
- { name: "Matrix", slug: "matrix" }
video: "T41rL0L3Pnw"
sidebar: sidebar:
label: 'Set Matrix Zeroes' label: 'Set Matrix Zeroes'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
::::warning ::::warning
You must do it in place. You must do it in place.
:::: ::::
@@ -95,7 +98,3 @@ class Solution:
for r in range(m): for r in range(m):
matrix[r][0] = 0 matrix[r][0] = 0
``` ```
## Explanation
<YouTube id="T41rL0L3Pnw" title="Set Matrix Zeroes - In-place - Leetcode 73" />
@@ -2,13 +2,17 @@
title: '230. Kth Smallest Element in a BST' title: '230. Kth Smallest Element in a BST'
description: Given the root of a binary search tree, and an integer k, return the k^th smallest value (1-indexed) of all the values of the nodes in the tree description: Given the root of a binary search tree, and an integer k, return the k^th smallest value (1-indexed) of all the values of the nodes in the tree
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Binary Search Tree", slug: "binary-search-tree" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "5LUXSvjmGCw"
sidebar: sidebar:
label: 'Kth Smallest Element in a BST' label: 'Kth Smallest Element in a BST'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
::::warning ::::warning
If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize? If the BST is modified often (i.e., we can do insert and delete operations) and you need to find the kth smallest frequently, how would you optimize?
:::: ::::
@@ -70,7 +74,3 @@ class Solution:
return cur.val return cur.val
cur = cur.right cur = cur.right
``` ```
## Explanation
<YouTube id="5LUXSvjmGCw" title="Kth Smallest Element in a BST - Leetcode 230 - Python" />
@@ -2,13 +2,19 @@
title: '235. Lowest Common Ancestor of a Binary Search Tree' title: '235. Lowest Common Ancestor of a Binary Search Tree'
description: Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST description: Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Binary Search Tree", slug: "binary-search-tree" }
- { name: "Binary Tree", slug: "binary-tree" }
- { name: "Binary Lifting", slug: "binary-lifting" }
- { name: "Lowest Common Ancestor", slug: "lowest-common-ancestor" }
video: "gs2LMfuOR9k"
sidebar: sidebar:
label: 'Lowest Common Ancestor of a Binary Search Tree' label: 'Lowest Common Ancestor of a Binary Search Tree'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8` - Input: `root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8`
- Output: `6` - Output: `6`
@@ -71,7 +77,3 @@ class Solution:
else: else:
return cur return cur
``` ```
## Explanation
<YouTube id="gs2LMfuOR9k" title="Lowest Common Ancestor of a Binary Search Tree - Leetcode 235 - Python" />
@@ -2,13 +2,17 @@
title: '98. Validate Binary Search Tree' title: '98. Validate Binary Search Tree'
description: Given the root of a binary tree, determine if it is a valid binary search tree (BST) description: Given the root of a binary tree, determine if it is a valid binary search tree (BST)
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Binary Search Tree", slug: "binary-search-tree" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "s6ATEkipzow"
sidebar: sidebar:
label: 'Validate Binary Search Tree' label: 'Validate Binary Search Tree'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [2,1,3]` - Input: `root = [2,1,3]`
- Output: `true` - Output: `true`
@@ -62,7 +66,3 @@ class Solution:
return valid(root, float("-inf"), float("inf")) return valid(root, float("-inf"), float("inf"))
``` ```
## Explanation
<YouTube id="s6ATEkipzow" title="Validate Binary Search Tree - Depth First Search - Leetcode 98" />
@@ -2,13 +2,18 @@
title: '215. Kth Largest Element in an Array' title: '215. Kth Largest Element in an Array'
description: Given an integer array nums and an integer k, return the k^th largest element in the array description: Given an integer array nums and an integer k, return the k^th largest element in the array
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Divide and Conquer", slug: "divide-and-conquer" }
- { name: "Sorting", slug: "sorting" }
- { name: "Heap (Priority Queue)", slug: "heap-priority-queue" }
- { name: "Quickselect", slug: "quickselect" }
video: "XEmy13g1Qxc"
sidebar: sidebar:
label: 'Kth Largest Element in an Array' label: 'Kth Largest Element in an Array'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [3,2,1,5,6,4], k = 2` - Input: `nums = [3,2,1,5,6,4], k = 2`
- Output: `5` - Output: `5`
@@ -54,7 +59,3 @@ class Solution:
return -heapq.heappop(nums) return -heapq.heappop(nums)
``` ```
## Explanation
<YouTube id="XEmy13g1Qxc" title="Kth Largest Element in an Array - Quick Select - Leetcode 215 - Python" />
@@ -2,13 +2,18 @@
title: '23. Merge k Sorted Lists' title: '23. Merge k Sorted Lists'
description: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order description: You are given an array of k linked-lists lists, each linked-list is sorted in ascending order
icon: dot icon: dot
topics:
- { name: "Linked List", slug: "linked-list" }
- { name: "Divide and Conquer", slug: "divide-and-conquer" }
- { name: "Heap (Priority Queue)", slug: "heap-priority-queue" }
- { name: "Merge Sort", slug: "merge-sort" }
- { name: "Tournament Sort", slug: "tournament-sort" }
video: "q5a5OiGbT6Q"
sidebar: sidebar:
label: 'Merge k Sorted Lists' label: 'Merge k Sorted Lists'
badge: 'Hard' badge: 'Hard'
--- ---
<Badge variant="accent">Linked List</Badge>
### Example 1: ### Example 1:
- Input: `lists = [[1,4,5],[1,3,4],[2,6]]` - Input: `lists = [[1,4,5],[1,3,4],[2,6]]`
- Output: `[1,1,2,3,4,4,5,6]` - Output: `[1,1,2,3,4,4,5,6]`
@@ -89,7 +94,3 @@ class Solution:
# Space: O(n) # Space: O(n)
return D.next return D.next
``` ```
## Explanation
<YouTube id="q5a5OiGbT6Q" title="Merge K Sorted Lists - Leetcode 23 - Python" />
@@ -2,13 +2,21 @@
title: '973. K Closest Points to Origin' title: '973. K Closest Points to Origin'
description: Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0) description: Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0)
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Math", slug: "math" }
- { name: "Divide and Conquer", slug: "divide-and-conquer" }
- { name: "Geometry", slug: "geometry" }
- { name: "Sorting", slug: "sorting" }
- { name: "Heap (Priority Queue)", slug: "heap-priority-queue" }
- { name: "Quickselect", slug: "quickselect" }
- { name: "K-D Tree", slug: "k-d-tree" }
video: "rI2EBUEMfTk"
sidebar: sidebar:
label: 'K Closest Points to Origin' label: 'K Closest Points to Origin'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `points = [[1,3],[-2,2]], k = 1` - Input: `points = [[1,3],[-2,2]], k = 1`
- Output: `[[-2,2]]` - Output: `[[-2,2]]`
@@ -64,7 +72,3 @@ class Solution:
return res return res
``` ```
## Explanation
<YouTube id="rI2EBUEMfTk" title="K Closest Points to Origin - Heap / Priority Queue - Leetcode 973 - Python" />
@@ -2,13 +2,16 @@
title: '102. Binary Tree Level Order Traversal' title: '102. Binary Tree Level Order Traversal'
description: Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level) description: Given the root of a binary tree, return the level order traversal of its nodes' values. (i.e., from left to right, level by level)
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "6ZnyEApgFYg"
sidebar: sidebar:
label: 'Binary Tree Level Order Traversal' label: 'Binary Tree Level Order Traversal'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [3,9,20,null,null,15,7]` - Input: `root = [3,9,20,null,null,15,7]`
- Output: `[[3],[9,20],[15,7]]` - Output: `[[3],[9,20],[15,7]]`
@@ -80,7 +83,3 @@ class Solution:
return res return res
``` ```
## Explanation
<YouTube id="6ZnyEApgFYg" title="Binary Tree Level Order Traversal - BFS - Leetcode 102" />
@@ -2,13 +2,17 @@
title: '1448. Count Good Nodes in Binary Tree' title: '1448. Count Good Nodes in Binary Tree'
description: Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X description: Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "7cp5imvDzl4"
sidebar: sidebar:
label: 'Count Good Nodes in Binary Tree' label: 'Count Good Nodes in Binary Tree'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [3,1,4,3,null,1,5]` - Input: `root = [3,1,4,3,null,1,5]`
- Output: `4` - Output: `4`
@@ -67,7 +71,3 @@ class Solution:
return dfs(root, root.val) return dfs(root, root.val)
``` ```
## Explanation
<YouTube id="7cp5imvDzl4" title="Microsoft's Most Asked Question 2021 - Count Good Nodes in a Binary Tree - Leetcode 1448 - Python" />
@@ -2,13 +2,17 @@
title: '199. Binary Tree Right Side View' title: '199. Binary Tree Right Side View'
description: Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom description: Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "d4zLyf32e3I"
sidebar: sidebar:
label: 'Binary Tree Right Side View' label: 'Binary Tree Right Side View'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [1,2,3,null,5,null,4]` - Input: `root = [1,2,3,null,5,null,4]`
- Output: `[1,3,4]` - Output: `[1,3,4]`
@@ -83,7 +87,3 @@ class Solution:
return res return res
``` ```
## Explanation
<YouTube id="d4zLyf32e3I" title="Binary Tree Right Side View - Breadth First Search - Leetcode 199" />
@@ -2,13 +2,17 @@
title: '104. Maximum Depth of Binary Tree' title: '104. Maximum Depth of Binary Tree'
description: Given the root of a binary tree, return its maximum depth description: Given the root of a binary tree, return its maximum depth
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "hTM3phVI6YQ"
sidebar: sidebar:
label: 'Maximum Depth of Binary Tree' label: 'Maximum Depth of Binary Tree'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [3,9,20,null,null,15,7]` - Input: `root = [3,9,20,null,null,15,7]`
- Output: `3` - Output: `3`
@@ -48,7 +52,3 @@ class Solution:
return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right)) return 1 + max(self.maxDepth(root.left), self.maxDepth(root.right))
``` ```
## Explanation
<YouTube id="hTM3phVI6YQ" title="Maximum Depth of Binary Tree - 3 Solutions - Leetcode 104 - Python" />
@@ -2,13 +2,17 @@
title: '226. Invert Binary Tree' title: '226. Invert Binary Tree'
description: Given the root of a binary tree, invert the tree, and return its root description: Given the root of a binary tree, invert the tree, and return its root
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
video: "OnSn2XEQ4MY"
sidebar: sidebar:
label: 'Invert Binary Tree' label: 'Invert Binary Tree'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [4,2,7,1,3,6,9]` - Input: `root = [4,2,7,1,3,6,9]`
- Output: `[4,7,2,9,6,3,1]` - Output: `[4,7,2,9,6,3,1]`
@@ -59,7 +63,3 @@ class Solution:
return root return root
``` ```
## Explanation
<YouTube id="OnSn2XEQ4MY" title="Invert Binary Tree - Depth First Search - Leetcode 226" />
@@ -2,13 +2,17 @@
title: '236. Lowest Common Ancestor of a Binary Tree' title: '236. Lowest Common Ancestor of a Binary Tree'
description: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree description: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree
icon: dot icon: dot
topics:
- { name: "Tree", slug: "tree" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Binary Tree", slug: "binary-tree" }
- { name: "Binary Lifting", slug: "binary-lifting" }
- { name: "Lowest Common Ancestor", slug: "lowest-common-ancestor" }
sidebar: sidebar:
label: 'Lowest Common Ancestor of a Binary Tree' label: 'Lowest Common Ancestor of a Binary Tree'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Tree</Badge>
### Example 1: ### Example 1:
- Input: `root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1` - Input: `root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1`
- Output: `3` - Output: `3`
@@ -2,13 +2,17 @@
title: '208. Implement Trie (Prefix Tree)' title: '208. Implement Trie (Prefix Tree)'
description: A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker description: A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Design", slug: "design" }
- { name: "Trie", slug: "trie" }
video: "oobqoCJlHA0"
sidebar: sidebar:
label: 'Implement Trie (Prefix Tree)' label: 'Implement Trie (Prefix Tree)'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `` - Input: ``
- Output: `` - Output: ``
@@ -107,7 +111,3 @@ class Trie:
# param_2 = obj.search(word) # param_2 = obj.search(word)
# param_3 = obj.startsWith(prefix) # param_3 = obj.startsWith(prefix)
``` ```
## Explanation
<YouTube id="oobqoCJlHA0" title="Implement Trie (Prefix Tree) - Leetcode 208" />
@@ -2,13 +2,17 @@
title: '211. Design Add and Search Words Data Structure' title: '211. Design Add and Search Words Data Structure'
description: Design a data structure that supports adding new words and finding if a string matches any previously added string description: Design a data structure that supports adding new words and finding if a string matches any previously added string
icon: dot icon: dot
topics:
- { name: "String", slug: "string" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Design", slug: "design" }
- { name: "Trie", slug: "trie" }
video: "BTf05gs_8iU"
sidebar: sidebar:
label: 'Design Add and Search Words Data Structure' label: 'Design Add and Search Words Data Structure'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">String</Badge>
### Constraints: ### Constraints:
- `1 <= word.length <= 25` - `1 <= word.length <= 25`
@@ -101,7 +105,3 @@ class WordDictionary:
# obj.addWord(word) # obj.addWord(word)
# param_3 = obj.search(word) # param_3 = obj.search(word)
``` ```
## Explanation
<YouTube id="BTf05gs_8iU" title="Design Add and Search Words Data Structure - Leetcode 211 - Python" />
@@ -2,13 +2,16 @@
title: '127. Word Ladder' title: '127. Word Ladder'
description: 'A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:' description: 'A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that:'
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "String", slug: "string" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Bidirectional Search", slug: "bidirectional-search" }
sidebar: sidebar:
label: 'Word Ladder' label: 'Word Ladder'
badge: 'Hard' badge: 'Hard'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]` - Input: `beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"]`
- Output: `5` - Output: `5`
@@ -2,13 +2,15 @@
title: '994. Rotting Oranges' title: '994. Rotting Oranges'
description: 'You are given an m x n grid where each cell can have one of three values:' description: 'You are given an m x n grid where each cell can have one of three values:'
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Matrix", slug: "matrix" }
sidebar: sidebar:
label: 'Rotting Oranges' label: 'Rotting Oranges'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `grid = [[2,1,1],[1,1,0],[0,1,1]]` - Input: `grid = [[2,1,1],[1,1,0],[0,1,1]]`
- Output: `4` - Output: `4`
@@ -2,13 +2,16 @@
title: '133. Clone Graph' title: '133. Clone Graph'
description: Given a reference of a node in a connected undirected graph description: Given a reference of a node in a connected undirected graph
icon: dot icon: dot
topics:
- { name: "Hash Table", slug: "hash-table" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Graph Theory", slug: "graph" }
sidebar: sidebar:
label: 'Clone Graph' label: 'Clone Graph'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Hash Table</Badge>
### Example 1: ### Example 1:
- Input: `adjList = [[2,4],[1,3],[2,4],[1,3]]` - Input: `adjList = [[2,4],[1,3],[2,4],[1,3]]`
- Output: `[[2,4],[1,3],[2,4],[1,3]]` - Output: `[[2,4],[1,3],[2,4],[1,3]]`
@@ -2,13 +2,17 @@
title: '200. Number of Islands' title: '200. Number of Islands'
description: Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands description: Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Union-Find", slug: "union-find" }
- { name: "Matrix", slug: "matrix" }
sidebar: sidebar:
label: 'Number of Islands' label: 'Number of Islands'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ]` - Input: `grid = [ ["1","1","1","1","0"], ["1","1","0","1","0"], ["1","1","0","0","0"], ["0","0","0","0","0"] ]`
- Output: `1` - Output: `1`
@@ -2,13 +2,16 @@
title: '417. Pacific Atlantic Water Flow' title: '417. Pacific Atlantic Water Flow'
description: There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges description: There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Matrix", slug: "matrix" }
sidebar: sidebar:
label: 'Pacific Atlantic Water Flow' label: 'Pacific Atlantic Water Flow'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 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]]` - 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]]` - Output: `[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]`
@@ -2,13 +2,17 @@
title: '207. Course Schedule' title: '207. Course Schedule'
description: 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 description: 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
icon: dot icon: dot
topics:
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Graph Theory", slug: "graph" }
- { name: "Topological Sort", slug: "topological-sort" }
- { name: "Directed Acyclic Graph", slug: "directed-acyclic-graph" }
sidebar: sidebar:
label: 'Course Schedule' label: 'Course Schedule'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Depth-First Search</Badge>
### Example 1: ### Example 1:
- Input: `numCourses = 2, prerequisites = [[1,0]]` - Input: `numCourses = 2, prerequisites = [[1,0]]`
- Output: `true` - Output: `true`
@@ -2,13 +2,16 @@
title: '210. Course Schedule II' title: '210. Course Schedule II'
description: 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 description: 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
icon: dot icon: dot
topics:
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Graph Theory", slug: "graph" }
- { name: "Topological Sort", slug: "topological-sort" }
sidebar: sidebar:
label: 'Course Schedule II' label: 'Course Schedule II'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Depth-First Search</Badge>
### Example 1: ### Example 1:
- Input: `numCourses = 2, prerequisites = [[1,0]]` - Input: `numCourses = 2, prerequisites = [[1,0]]`
- Output: `[0,1]` - Output: `[0,1]`
@@ -2,13 +2,16 @@
title: '323. Number of Connected Components in an Undirected Graph' title: '323. Number of Connected Components in an Undirected Graph'
description: You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph description: You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi in the graph
icon: dot icon: dot
topics:
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Union-Find", slug: "union-find" }
- { name: "Graph Theory", slug: "graph" }
sidebar: sidebar:
label: 'Number of Connected Components in an Undirected Graph' label: 'Number of Connected Components in an Undirected Graph'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Depth-First Search</Badge>
### Example 1: ### Example 1:
- Input: `n = 5, edges = [[0,1],[1,2],[3,4]]` - Input: `n = 5, edges = [[0,1],[1,2],[3,4]]`
- Output: `2` - Output: `2`
@@ -2,13 +2,16 @@
title: '684. Redundant Connection' title: '684. Redundant Connection'
description: In this problem, a tree is an undirected graph that is connected and has no cycles description: In this problem, a tree is an undirected graph that is connected and has no cycles
icon: dot icon: dot
topics:
- { name: "Depth-First Search", slug: "depth-first-search" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Union-Find", slug: "union-find" }
- { name: "Graph Theory", slug: "graph" }
sidebar: sidebar:
label: 'Redundant Connection' label: 'Redundant Connection'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Depth-First Search</Badge>
### Example 1: ### Example 1:
- Input: `edges = [[1,2],[1,3],[2,3]]` - Input: `edges = [[1,2],[1,3],[2,3]]`
- Output: `[2,3]` - Output: `[2,3]`
@@ -2,13 +2,14 @@
title: '198. House Robber' title: '198. House Robber'
description: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night description: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Dynamic Programming", slug: "dynamic-programming" }
sidebar: sidebar:
label: 'House Robber' label: 'House Robber'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [1,2,3,1]` - Input: `nums = [1,2,3,1]`
- Output: `4` - Output: `4`
@@ -2,13 +2,17 @@
title: '322. Coin Change' title: '322. Coin Change'
description: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money description: You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Dynamic Programming", slug: "dynamic-programming" }
- { name: "Breadth-First Search", slug: "breadth-first-search" }
- { name: "Knapsack Problem", slug: "knapsack-problem" }
- { name: "Complete Knapsack", slug: "complete-knapsack" }
sidebar: sidebar:
label: 'Coin Change' label: 'Coin Change'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `coins = [1,2,5], amount = 11` - Input: `coins = [1,2,5], amount = 11`
- Output: `3` - Output: `3`
@@ -2,13 +2,15 @@
title: '70. Climbing Stairs' title: '70. Climbing Stairs'
description: You are climbing a staircase. It takes n steps to reach the top description: You are climbing a staircase. It takes n steps to reach the top
icon: dot icon: dot
topics:
- { name: "Math", slug: "math" }
- { name: "Dynamic Programming", slug: "dynamic-programming" }
- { name: "Memoization", slug: "memoization" }
sidebar: sidebar:
label: 'Climbing Stairs' label: 'Climbing Stairs'
badge: 'Easy' badge: 'Easy'
--- ---
<Badge variant="accent">Math</Badge>
### Example 1: ### Example 1:
- Input: `n = 2` - Input: `n = 2`
- Output: `2` - Output: `2`
@@ -2,13 +2,14 @@
title: '39. Combination Sum' title: '39. Combination Sum'
description: Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order description: Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen numbers sum to target. You may return the combinations in any order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
sidebar: sidebar:
label: 'Combination Sum' label: 'Combination Sum'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `candidates = [2,3,6,7], target = 7` - Input: `candidates = [2,3,6,7], target = 7`
- Output: `[[2,2,3],[7]]` - Output: `[[2,2,3],[7]]`
@@ -2,13 +2,14 @@
title: '46. Permutations' title: '46. Permutations'
description: Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order description: Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
sidebar: sidebar:
label: 'Permutations' label: 'Permutations'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [1,2,3]` - Input: `nums = [1,2,3]`
- Output: `[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]` - Output: `[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]`
@@ -2,13 +2,15 @@
title: '78. Subsets' title: '78. Subsets'
description: Given an integer array nums of unique elements, return all possible subsets (the power set) description: Given an integer array nums of unique elements, return all possible subsets (the power set)
icon: dot icon: dot
topics:
- { name: "Array", slug: "array" }
- { name: "Backtracking", slug: "backtracking" }
- { name: "Bit Manipulation", slug: "bit-manipulation" }
sidebar: sidebar:
label: 'Subsets' label: 'Subsets'
badge: 'Medium' badge: 'Medium'
--- ---
<Badge variant="accent">Array</Badge>
### Example 1: ### Example 1:
- Input: `nums = [1,2,3]` - Input: `nums = [1,2,3]`
- Output: `[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]` - Output: `[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]`
+8
View File
@@ -0,0 +1,8 @@
---
title: "Array"
list: "https://leetcode.com/problem-list/array/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Array.
:::
@@ -0,0 +1,8 @@
---
title: "Bidirectional Search"
list: "https://leetcode.com/problem-list/bidirectional-search/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Bidirectional Search.
:::
@@ -0,0 +1,8 @@
---
title: "Binary Lifting"
list: "https://leetcode.com/problem-list/binary-lifting/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Binary Lifting.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Binary Tree"
list: "https://leetcode.com/problem-list/binary-tree/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Binary Tree.
:::
@@ -0,0 +1,8 @@
---
title: "Bit Manipulation"
list: "https://leetcode.com/problem-list/bit-manipulation/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Bit Manipulation.
:::
@@ -0,0 +1,8 @@
---
title: "Bracket Sequences"
list: "https://leetcode.com/problem-list/bracket-sequences/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Bracket Sequences.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Bucket Sort"
list: "https://leetcode.com/problem-list/bucket-sort/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Bucket Sort.
:::
@@ -0,0 +1,8 @@
---
title: "Complete Knapsack"
list: "https://leetcode.com/problem-list/complete-knapsack/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Complete Knapsack.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Counting"
list: "https://leetcode.com/problem-list/counting/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Counting.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Design"
list: "https://leetcode.com/problem-list/design/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Design.
:::
@@ -0,0 +1,8 @@
---
title: "Directed Acyclic Graph"
list: "https://leetcode.com/problem-list/directed-acyclic-graph/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Directed Acyclic Graph.
:::
@@ -0,0 +1,8 @@
---
title: "Divide and Conquer"
list: "https://leetcode.com/problem-list/divide-and-conquer/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Divide and Conquer.
:::
@@ -0,0 +1,8 @@
---
title: "Doubly-Linked List"
list: "https://leetcode.com/problem-list/doubly-linked-list/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Doubly-Linked List.
:::
@@ -0,0 +1,8 @@
---
title: "Floyd's Cycle Finding Algorithm"
list: "https://leetcode.com/problem-list/floyds-cycle-finding-algorithm/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Floyd's Cycle Finding Algorithm.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Geometry"
list: "https://leetcode.com/problem-list/geometry/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Geometry.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Graph Theory"
list: "https://leetcode.com/problem-list/graph/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Graph Theory.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "K-D Tree"
list: "https://leetcode.com/problem-list/k-d-tree/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged K-D Tree.
:::
@@ -0,0 +1,8 @@
---
title: "Knapsack Problem"
list: "https://leetcode.com/problem-list/knapsack-problem/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Knapsack Problem.
:::
@@ -0,0 +1,8 @@
---
title: "Lowest Common Ancestor"
list: "https://leetcode.com/problem-list/lowest-common-ancestor/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Lowest Common Ancestor.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Math"
list: "https://leetcode.com/problem-list/math/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Math.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Memoization"
list: "https://leetcode.com/problem-list/memoization/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Memoization.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Merge Sort"
list: "https://leetcode.com/problem-list/merge-sort/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Merge Sort.
:::
+3
View File
@@ -0,0 +1,3 @@
import { defineMeta } from "blume";
export default defineMeta({ title: "Guides" });
+8
View File
@@ -0,0 +1,8 @@
---
title: "Queue"
list: "https://leetcode.com/problem-list/queue/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Queue.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Quickselect"
list: "https://leetcode.com/problem-list/quickselect/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Quickselect.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Recursion"
list: "https://leetcode.com/problem-list/recursion/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Recursion.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Simulation"
list: "https://leetcode.com/problem-list/simulation/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Simulation.
:::
+8
View File
@@ -0,0 +1,8 @@
---
title: "Sorting"
list: "https://leetcode.com/problem-list/sorting/"
---
:::note
This guide has not been written yet. The LeetCode list above has every problem tagged Sorting.
:::
Loaded 100 of 104 files, more files were not shown because too many files have changed in this diff. Show more