-
Notifications
You must be signed in to change notification settings - Fork 0
Add Vertical Order Traversal of a Binary Tree solution #220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
leetcode/hard/0987-vertical-order-traversal-of-a-binary-tree/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # [Vertical Order Traversal of a Binary Tree](https://leetcode.com/problems/vertical-order-traversal-of-a-binary-tree)  | ||
|
|
||
| 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 | ||
|
|
||
|  | ||
|
|
||
| ```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 | ||
|
|
||
|  | ||
|
|
||
| ```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 | ||
|
|
||
|  | ||
|
|
||
| ```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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pertrai1/coding-challenges
Length of output: 109
🌐 Web query:
LeetCode problem number "Vertical Order Traversal of a Binary Tree"💡 Result:
LeetCode problem number: 987 — Vertical Order Traversal of a Binary Tree [1][3]
Correct the LeetCode problem ID and update the total count.
The problem ID for "Vertical Order Traversal of a Binary Tree" is 987, not 1029. Additionally, the LeetCode total on line 9 should be 173, not 172, to match the actual number of problems in the directory structure (81 easy + 77 medium + 15 hard).
🤖 Prompt for AI Agents