Solution #199 - Daniel/Edited - 17.03.2025#38
Open
danzang100 wants to merge 3 commits intoDijkstra-Edu:masterfrom
Open
Solution #199 - Daniel/Edited - 17.03.2025#38danzang100 wants to merge 3 commits intoDijkstra-Edu:masterfrom
danzang100 wants to merge 3 commits intoDijkstra-Edu:masterfrom
Conversation
JRS296
reviewed
Mar 21, 2025
Comment on lines
+1
to
+16
| Left View of tree. | ||
|
|
||
| Brute Force Approach: | ||
|
|
||
| 1. Perform a complete level order traversal of the tree and maintain a matrix of all nodes visited by level. | ||
| 2. Choose only the first element for each level and return. | ||
|
|
||
| Time Complexity: O(n) | ||
| Space Complexity: O(n) | ||
|
|
||
| Optimal Approach: | ||
|
|
||
| 1. Perform DFS traversal of the tree prioritising the left subtree each time. | ||
| 2. Take the first element of each level and return. | ||
|
|
||
| For right view, repeat the same but take the last element of the matrix or perform DFS with the right subtree prioritised. |
Member
There was a problem hiding this comment.
Can be much better! utilize Markdown and try to explain each step + Complexities.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Solution and Explanation added.