Skip to content

BFS 2-1 done#615

Open
Tanmay-Nalawade wants to merge 2 commits into
super30admin:mainfrom
Tanmay-Nalawade:main
Open

BFS 2-1 done#615
Tanmay-Nalawade wants to merge 2 commits into
super30admin:mainfrom
Tanmay-Nalawade:main

Conversation

@Tanmay-Nalawade
Copy link
Copy Markdown

No description provided.

@super30admin
Copy link
Copy Markdown
Owner

Your solution for the "Rotting Oranges" problem is mostly correct and well-implemented. You used BFS appropriately, which is the standard approach for this problem. Here are some points to consider:

  1. Correctness: Your solution handles the basic cases correctly. However, note that you increment time at the start of each level, which is correct. But you do not break early when all fresh oranges have been rotted during a level. This means that if the last orange is rotted early in a level, you still process the entire level (which might include other rotten oranges that don't affect fresh ones). This doesn't change the result but is slightly inefficient.

  2. Early Termination: Consider adding a check inside the inner loop to break out if nFresh becomes 0. For example, after decrementing nFresh, you can check if it is 0 and break out of the inner loop and then the outer loop. This would optimize the code.

  3. Directions Definition: You define the directions list inside the for loop that processes each node. This means that for every node, you create a new list of directions. It would be more efficient to define the directions list outside the while loop, so it is created only once.

  4. Code Clarity: Your code is clear and

@super30admin
Copy link
Copy Markdown
Owner

Evaluation completed, but no feedback text was generated.

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