Skip to content

Done with BFS-1#1616

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

Done with BFS-1#1616
Mukul585 wants to merge 1 commit intosuper30admin:masterfrom
Mukul585:master

Conversation

@Mukul585
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

It seems there might have been a mix-up in the files. The problem you were asked to solve was "Level Order Traversal in Binary tree", but your solution is for "Course Schedule" (which is a topological sort problem).

For the level order traversal problem, you need to traverse a binary tree level by level and return the values in a list of lists. The typical approach uses a queue to perform a breadth-first search (BFS). Here's a brief outline of how you might approach it:

  • If the root is null, return an empty list.
  • Create a queue and add the root node.
  • While the queue is not empty:
    • Get the current size of the queue (which represents the number of nodes at the current level).
    • Create a temporary list to store the values of the nodes at the current level.
    • For each node in the current level:
      • Remove the node from the queue and add its value to the temporary list.
      • If the node has left child, add it to the queue.
      • If the node has right child, add it to the queue.
    • Add the temporary list to the result.

Please ensure you are solving the correct problem. Double-check the problem statement and the expected input and output.

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