From e58b29a6f52bf9b4ee3b5e6fdc0bcdf76e0d4f0d Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Sat, 31 Jan 2026 09:27:44 -0500 Subject: [PATCH 1/4] Add Vertical Order Traversal of a Binary Tree solution --- README.md | 8 ++- .../README.md | 57 +++++++++++++++++++ ...rtical-order-traversal-of-a-binary-tree.ts | 41 +++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md create mode 100644 leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts diff --git a/README.md b/README.md index d25812a..01809cd 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A comprehensive collection of coding challenges from multiple platforms for lear | Platform | Focus Area | Problems Solved | | ------------------------------- | ---------------------------- | --------------- | -| [LeetCode](#leetcode) | Data Structures & Algorithms | 171 | +| [LeetCode](#leetcode) | Data Structures & Algorithms | 172 | | [GreatFrontEnd](#greatfrontend) | Frontend Engineering | 15 | ## Platforms @@ -287,7 +287,7 @@ Various places where I enjoy practicing solving coding challenges:
-Hard Problems (14 solved) +Hard Problems (15 solved) ### Array & Dynamic Programming @@ -295,6 +295,10 @@ Various places where I enjoy practicing solving coding challenges: - [0689 - Maximum Sum of 3 Non-Overlapping Subarrays](./leetcode/hard/0689-maximum-sum-of-3-non-overlapping-subarrays) ![Hard](https://img.shields.io/badge/Hard-red) - [1034 - Subarrays with K Different Integers](./leetcode/hard/1034-subarrays-with-k-different-integers) ![Hard](https://img.shields.io/badge/Hard-red) +### Tree Problems + +- [1029 - Vertical Order Traversal of a Binary Tree](./leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree) ![Hard](https://img.shields.io/badge/Hard-red) + ### Backtracking & Trie - [0212 - Word Search II](./leetcode/hard/0212-word-search-ii) ![Hard](https://img.shields.io/badge/Hard-red) diff --git a/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md b/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md new file mode 100644 index 0000000..f5c9b03 --- /dev/null +++ b/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md @@ -0,0 +1,57 @@ +# [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree) ![Shield](https://img.shields.io/badge/Hard-red) + +Given the `root` of a binary tree, calculate the **vertical order traversal** of the binary tree. + +For each node at position `(row, col)`, its left and right children will be at positions `(row + 1, col - 1)` and `(row + 1, col + 1)` respectively. The root of the tree is at `(0, 0)`. + +The **vertical order traversal** of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values. + +Return _the **vertical order traversal** of the binary tree_. + +## Example 1 + +![tree](https://assets.leetcode.com/uploads/2021/01/29/vtree1.jpg) + +```bash +Input: root = [3,9,20,null,null,15,7] +Output: [[9],[3,15],[20],[7]] +Explanation: +Column -1: Only node 9 is in this column. +Column 0: Nodes 3 and 15 are in this column in that order from top to bottom. +Column 1: Only node 20 is in this column. +Column 2: Only node 7 is in this column. +``` + +## Example 2 + +![tree](https://assets.leetcode.com/uploads/2021/01/29/vtree2.jpg) + +```bash +Input: root = [1,2,3,4,5,6,7] +Output: [[4],[2],[1,5,6],[3],[7]] +Explanation: +Column -2: Only node 4 is in this column. +Column -1: Only node 2 is in this column. +Column 0: Nodes 1, 5, and 6 are in this column. + 1 is at the top, so it comes first. + 5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6. +Column 1: Only node 3 is in this column. +Column 2: Only node 7 is in this column. +``` + +## Example 3 + +![tree](https://assets.leetcode.com/uploads/2021/01/29/vtree3.jpg) + +```bash +Input: root = [1,2,3,4,6,5,7] +Output: [[4],[2],[1,5,6],[3],[7]] +Explanation: +This case is the exact same as example 2, but with nodes 5 and 6 swapped. +Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values. +``` + +## Constraints + +- The number of nodes in the tree is in the range `[1, 1000]`. +- `0 <= Node.val <= 1000` diff --git a/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts b/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts new file mode 100644 index 0000000..d07f60b --- /dev/null +++ b/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts @@ -0,0 +1,41 @@ +export class TreeNode { + val: number; + left: TreeNode | null; + right: TreeNode | null; + constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { + this.val = val === undefined ? 0 : val; + this.left = left === undefined ? null : left; + this.right = right === undefined ? null : right; + } +} + +export function verticalTraversal(root: TreeNode | null): number[][] { + // initialize a map where: + // key = column index + // value = array of [row, node.val] + const valueMap = new Map(); + + function traverse(node: TreeNode | null, row: number, col: number) { + if (!node) return; + + // add the current node to the map + if (!valueMap.has(col)) { + valueMap.set(col, []); + } + valueMap.get(col)!.push([row, node.val]); + // recurse left (col - 1) and right (col + 1) with row + 1 + traverse(node.left, row + 1, col - 1); + traverse(node.right, row + 1, col + 1); + } + + traverse(root, 0, 0); + + // sort columns left -> right + const sortedCols = Array.from(valueMap.keys()).sort((a, b) => a - b); + + return sortedCols.map((col) => { + // sort column entries: row -> value + const sortedNodes = valueMap.get(col)!.sort((a, b) => a[0] - b[0] || a[1] - b[1]); + return sortedNodes.map((n) => n[1]); + }); +} From 8abff189391e50df923d793c8354c2e356506f6b Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Sat, 31 Jan 2026 09:28:08 -0500 Subject: [PATCH 2/4] remove moved code --- .../README.md | 57 ------------------- ...rtical-order-traversal-of-a-binary-tree.ts | 44 -------------- 2 files changed, 101 deletions(-) delete mode 100644 1029-vertical-order-traversal-of-a-binary-tree/README.md delete mode 100644 1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts diff --git a/1029-vertical-order-traversal-of-a-binary-tree/README.md b/1029-vertical-order-traversal-of-a-binary-tree/README.md deleted file mode 100644 index eb994a9..0000000 --- a/1029-vertical-order-traversal-of-a-binary-tree/README.md +++ /dev/null @@ -1,57 +0,0 @@ - -# [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree) ![](https://img.shields.io/badge/Hard-red) - -

Given the root of a binary tree, calculate the vertical order traversal of the binary tree.

- -

For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0).

- -

The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values.

- -

Return the vertical order traversal of the binary tree.

- -

 

-

Example 1:

- -
-Input: root = [3,9,20,null,null,15,7]
-Output: [[9],[3,15],[20],[7]]
-Explanation:
-Column -1: Only node 9 is in this column.
-Column 0: Nodes 3 and 15 are in this column in that order from top to bottom.
-Column 1: Only node 20 is in this column.
-Column 2: Only node 7 is in this column.
- -

Example 2:

- -
-Input: root = [1,2,3,4,5,6,7]
-Output: [[4],[2],[1,5,6],[3],[7]]
-Explanation:
-Column -2: Only node 4 is in this column.
-Column -1: Only node 2 is in this column.
-Column 0: Nodes 1, 5, and 6 are in this column.
-          1 is at the top, so it comes first.
-          5 and 6 are at the same position (2, 0), so we order them by their value, 5 before 6.
-Column 1: Only node 3 is in this column.
-Column 2: Only node 7 is in this column.
-
- -

Example 3:

- -
-Input: root = [1,2,3,4,6,5,7]
-Output: [[4],[2],[1,5,6],[3],[7]]
-Explanation:
-This case is the exact same as example 2, but with nodes 5 and 6 swapped.
-Note that the solution remains the same since 5 and 6 are in the same location and should be ordered by their values.
-
- -

 

-

Constraints:

- -
    -
  • The number of nodes in the tree is in the range [1, 1000].
  • -
  • 0 <= Node.val <= 1000
  • -
- - \ No newline at end of file diff --git a/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts b/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts deleted file mode 100644 index 45d5d01..0000000 --- a/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Definition for a binary tree node. - * class TreeNode { - * val: number - * left: TreeNode | null - * right: TreeNode | null - * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { - * this.val = (val===undefined ? 0 : val) - * this.left = (left===undefined ? null : left) - * this.right = (right===undefined ? null : right) - * } - * } - */ - -function verticalTraversal(root: TreeNode | null): number[][] { - // initialize a map where: - // key = column index - // value = array of [row, node.val] - const valueMap = new Map(); - - function traverse(node: TreeNode | null, row: number, col: number) { - if (!node) return; - - // add the current node to the map - if (!valueMap.has(col)) { - valueMap.set(col, []); - } - valueMap.get(col)!.push([row, node.val]); - // recurse left (col - 1) and right (col + 1) with row + 1 - traverse(node.left, row + 1, col - 1); - traverse(node.right, row + 1, col + 1); - } - - traverse(root, 0, 0); - - // sort columns left -> right - const sortedCols = Array.from(valueMap.keys()).sort((a, b) => a - b); - - return sortedCols.map((col) => { - // sort column entries: row -> value - const sortedNodes = valueMap.get(col).sort((a, b) => a[0] - b[0] || a[1] - b[1]); - return sortedNodes.map((n) => n[1]); - }); -}; \ No newline at end of file From 22acee80d2ccdd43541ebed4e5f23369cb8f9185 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Sat, 31 Jan 2026 10:48:27 -0500 Subject: [PATCH 3/4] update problem number --- README.md | 2 +- .../README.md | 0 .../vertical-order-traversal-of-a-binary-tree.ts | 0 3 files changed, 1 insertion(+), 1 deletion(-) rename leetcode/hard/{1029-vertical-order-traversal-of-a-binary-tree => 0987-vertical-order-traversal-of-a-binary-tree}/README.md (100%) rename leetcode/hard/{1029-vertical-order-traversal-of-a-binary-tree => 0987-vertical-order-traversal-of-a-binary-tree}/vertical-order-traversal-of-a-binary-tree.ts (100%) diff --git a/README.md b/README.md index 01809cd..31be0e7 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ Various places where I enjoy practicing solving coding challenges: ### Tree Problems -- [1029 - Vertical Order Traversal of a Binary Tree](./leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree) ![Hard](https://img.shields.io/badge/Hard-red) +- [0987 - Vertical Order Traversal of a Binary Tree](./leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree) ![Hard](https://img.shields.io/badge/Hard-red) ### Backtracking & Trie diff --git a/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md b/leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree/README.md similarity index 100% rename from leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/README.md rename to leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree/README.md diff --git a/leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts b/leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts similarity index 100% rename from leetcode/hard/1029-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts rename to leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree/vertical-order-traversal-of-a-binary-tree.ts From c4720cbf3f6eac9685646fb39fa201b2f23078b5 Mon Sep 17 00:00:00 2001 From: rsimpson2 Date: Sat, 31 Jan 2026 10:50:43 -0500 Subject: [PATCH 4/4] backup some github workflows --- .github/{workflows => backups}/code-quality.yml | 0 .github/{workflows => backups}/openai-codex-pr-review.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/{workflows => backups}/code-quality.yml (100%) rename .github/{workflows => backups}/openai-codex-pr-review.yml (100%) diff --git a/.github/workflows/code-quality.yml b/.github/backups/code-quality.yml similarity index 100% rename from .github/workflows/code-quality.yml rename to .github/backups/code-quality.yml diff --git a/.github/workflows/openai-codex-pr-review.yml b/.github/backups/openai-codex-pr-review.yml similarity index 100% rename from .github/workflows/openai-codex-pr-review.yml rename to .github/backups/openai-codex-pr-review.yml