Skip to content

Solution #199 - Daniel/Edited - 17.03.2025 #38

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

danzang100
Copy link

Solution and Explanation added.

@JRS296 JRS296 requested a review from SSexpl March 17, 2025 21:01
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be much better! utilize Markdown and try to explain each step + Complexities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants