From 244f889da653397e5cd981ba8b75e4ba3be5693a Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Mon, 6 Jul 2026 12:10:24 -0700 Subject: [PATCH 1/5] fix clone graph dfs c++ map usage --- articles/clone-graph.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/articles/clone-graph.md b/articles/clone-graph.md index 760c16e37..bae2d9b6c 100644 --- a/articles/clone-graph.md +++ b/articles/clone-graph.md @@ -6,7 +6,7 @@ Before attempting this problem, you should be comfortable with: --- -## 1. Depth First Seacrh +## 1. Depth First Search ### Intuition The graph may contain **cycles**, so we cannot simply copy nodes recursively without remembering what we've already copied. @@ -130,11 +130,11 @@ public: class Solution { public: Node* cloneGraph(Node* node) { - map oldToNew; + unordered_map oldToNew; return dfs(node, oldToNew); } - Node* dfs(Node* node, map& oldToNew) { + Node* dfs(Node* node, unordered_map& oldToNew) { if (node == nullptr) { return nullptr; } From 90e1f4b7b83998146854ec3e746132363b86cd10 Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Mon, 6 Jul 2026 13:04:09 -0700 Subject: [PATCH 2/5] Fix Rust Word Search II backtracking article snippet --- articles/search-for-word-ii.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/articles/search-for-word-ii.md b/articles/search-for-word-ii.md index 3e82ba160..8c51c2568 100644 --- a/articles/search-for-word-ii.md +++ b/articles/search-for-word-ii.md @@ -384,7 +384,7 @@ impl Solution { if found { break; } for c in 0..cols { if board[r][c] != word_chars[0] { continue; } - if Self::backtrack(&mut board, r, c, &word_chars, 0) { + if Self::backtrack(&mut board, r as i32, c as i32, &word_chars, 0) { res.push(word.clone()); found = true; break; From 1a36ba62dae7817aab5f3213a2c8aa63d2fe4772 Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Mon, 6 Jul 2026 14:15:11 -0700 Subject: [PATCH 3/5] clarify is-anagram linear complexity --- articles/is-anagram.md | 8 ++++---- hints/is-anagram.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/articles/is-anagram.md b/articles/is-anagram.md index a707d2c54..b1d9c1bc6 100644 --- a/articles/is-anagram.md +++ b/articles/is-anagram.md @@ -375,10 +375,10 @@ impl Solution { ### Time & Space Complexity -- Time complexity: $O(n + m)$ +- Time complexity: $O(n)$ - Space complexity: $O(1)$ since we have at most $26$ different characters. -> Where $n$ is the length of string $s$ and $m$ is the length of string $t$. +> Where $n$ is the length of the strings after the early length check. --- @@ -603,10 +603,10 @@ impl Solution { ### Time & Space Complexity -- Time complexity: $O(n + m)$ +- Time complexity: $O(n)$ - Space complexity: $O(1)$ since we have at most $26$ different characters. -> Where $n$ is the length of string $s$ and $m$ is the length of string $t$. +> Where $n$ is the length of the strings after the early length check. --- diff --git a/hints/is-anagram.md b/hints/is-anagram.md index e775554df..58f51e28e 100644 --- a/hints/is-anagram.md +++ b/hints/is-anagram.md @@ -2,7 +2,7 @@
Recommended Time & Space Complexity

- You should aim for a solution with O(n + m) time and O(1) space, where n is the length of the string s and m is the length of the string t. + You should aim for a solution with O(n) time and O(1) space, where n is the length of the strings after checking that their lengths are equal.

From e0dc62b771adbddbd46fba3ee062f13b9c30cdd7 Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Mon, 6 Jul 2026 16:26:04 -0700 Subject: [PATCH 4/5] Fix preorder/inorder DFS space complexity note --- articles/binary-tree-from-preorder-and-inorder-traversal.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/articles/binary-tree-from-preorder-and-inorder-traversal.md b/articles/binary-tree-from-preorder-and-inorder-traversal.md index be7f8b159..b362d585d 100644 --- a/articles/binary-tree-from-preorder-and-inorder-traversal.md +++ b/articles/binary-tree-from-preorder-and-inorder-traversal.md @@ -332,7 +332,7 @@ impl Solution { ### Time & Space Complexity - Time complexity: $O(n ^ 2)$ -- Space complexity: $O(n)$ +- Space complexity: $O(n ^ 2)$ in the worst case due to copied subarrays; the recursion stack alone is $O(n)$. --- From 8b82b253e636964a1a85ce051d4ec6d40c7b470e Mon Sep 17 00:00:00 2001 From: ranveersingh2718 Date: Mon, 6 Jul 2026 16:55:07 -0700 Subject: [PATCH 5/5] Fix Meeting Rooms III heap solutions and complexity --- articles/meeting-rooms-iii.md | 153 +++++++++++++++++++++++++--------- 1 file changed, 113 insertions(+), 40 deletions(-) diff --git a/articles/meeting-rooms-iii.md b/articles/meeting-rooms-iii.md index fafa26eb2..47b8e9078 100644 --- a/articles/meeting-rooms-iii.md +++ b/articles/meeting-rooms-iii.md @@ -371,12 +371,13 @@ impl Solution { } } - meeting_count - .iter() - .enumerate() - .max_by_key(|&(_, &count)| count) - .unwrap() - .0 as i32 + let mut max_room = 0; + for i in 1..n { + if meeting_count[i] > meeting_count[max_room] { + max_room = i; + } + } + max_room as i32 } } ``` @@ -736,44 +737,110 @@ class Solution { ``` ```swift +struct MinHeap { + private var heap: [T] = [] + private let areSorted: (T, T) -> Bool + + init(_ areSorted: @escaping (T, T) -> Bool) { + self.areSorted = areSorted + } + + var isEmpty: Bool { + heap.isEmpty + } + + var peek: T? { + heap.first + } + + mutating func push(_ value: T) { + heap.append(value) + siftUp(heap.count - 1) + } + + mutating func pop() -> T? { + guard !heap.isEmpty else { + return nil + } + if heap.count == 1 { + return heap.removeLast() + } + + let value = heap[0] + let last = heap.removeLast() + heap[0] = last + siftDown(0) + return value + } + + private mutating func siftUp(_ index: Int) { + var child = index + var parent = (child - 1) / 2 + + while child > 0 && areSorted(heap[child], heap[parent]) { + heap.swapAt(child, parent) + child = parent + parent = (child - 1) / 2 + } + } + + private mutating func siftDown(_ index: Int) { + var parent = index + + while true { + let left = 2 * parent + 1 + let right = left + 1 + var candidate = parent + + if left < heap.count && areSorted(heap[left], heap[candidate]) { + candidate = left + } + if right < heap.count && areSorted(heap[right], heap[candidate]) { + candidate = right + } + if candidate == parent { + return + } + + heap.swapAt(parent, candidate) + parent = candidate + } + } +} + class Solution { func mostBooked(_ n: Int, _ meetings: [[Int]]) -> Int { let meetings = meetings.sorted { $0[0] < $1[0] } - var available = Array(0..(<) + var used = MinHeap<(end: Int64, room: Int)> { + if $0.end == $1.end { + return $0.room < $1.room + } + return $0.end < $1.end } + var count = [Int](repeating: 0, count: n) - func heapifyUsed() { - used.sort { ($0.end, $0.room) < ($1.end, $1.room) } + for room in 0.. count[max_room] { + max_room = i; + } + } + max_room as i32 } } ``` @@ -843,7 +911,11 @@ impl Solution { ### Time & Space Complexity -- Time complexity: $O(m\log m + m \log n)$ +- Time complexity: $O(m \log m + (m + n) \log n)$ + - Sorting the meetings costs $O(m \log m)$. + - Initializing `available` by inserting `n` rooms one at a time is bounded by $O(n \log n)$. + - Across all meetings, heap operations cost $O(m \log n)$. + - The Python block starts with an already heap-ordered list, so its initialization is $O(n)$, but the shared bound above applies across the implementations. - Space complexity: $O(n)$ > Where $n$ is the number of rooms and $m$ is the number of meetings. @@ -1206,12 +1278,13 @@ impl Solution { count[room] += 1; } - count - .iter() - .enumerate() - .max_by_key(|&(_, &c)| c) - .unwrap() - .0 as i32 + let mut max_room = 0; + for i in 1..n { + if count[i] > count[max_room] { + max_room = i; + } + } + max_room as i32 } } ```