Skip to content

"BFS-2 done"#1586

Open
Sahithipsl470 wants to merge 1 commit intosuper30admin:masterfrom
Sahithipsl470:master
Open

"BFS-2 done"#1586
Sahithipsl470 wants to merge 1 commit intosuper30admin:masterfrom
Sahithipsl470:master

Conversation

@Sahithipsl470
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Your solution for the "Right Side View" problem is excellent. You correctly implemented a DFS approach with a modified pre-order traversal (right before left) and used the level to determine when to add the node value to the result. This is efficient and intuitive.

Strengths:

  • You provided clear comments explaining your approach.
  • The code is concise and easy to read.
  • You handled the base case appropriately.

Areas for Improvement:

  • Although your solution is correct, note that the reference solution uses BFS (level-order traversal), which is another common approach. Both DFS and BFS are acceptable, but it's good to be familiar with both.
  • In the Java solution, consider adding null checks for the result list in the helper method, though it is not strictly necessary since the list is passed from the main method.
  • For consistency, you might want to use the same language for both problems unless required otherwise.

Since you included an extra problem (Cousins in Binary Tree), ensure in the future to only provide the solution for the problem being evaluated unless asked for multiple. However, your solutions for that problem are also correct.

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