Skip to content

Completed - #1661

Open
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:leetcode102and207
Open

Completed#1661
allurkarsneha wants to merge 1 commit into
super30admin:masterfrom
allurkarsneha:leetcode102and207

Conversation

@allurkarsneha

Copy link
Copy Markdown

No description provided.

@super30admin

Copy link
Copy Markdown
Owner

Binary Tree Level Order Traversal (Problem 1- Leetcode102.py)

Strengths:

  • Your solution correctly implements BFS for level order traversal
  • Good use of deque for O(1) popleft operations
  • The code is clean and follows Python conventions
  • You correctly handle the edge case of an empty tree
  • The algorithm matches the optimal approach

Areas for Improvement:

  1. Remove commented-out code: The commented DFS approach should be removed for cleaner code. If you want to keep it as an alternative, put it in a separate function or commit.
  2. Add type hints: Python supports type hints which would make the code more professional:
    def levelOrder(self, root: Optional[TreeNode]) -> List[List[int]]:
  3. Consider edge case handling: While your solution handles root is None, you could also handle the case where the input might not be a TreeNode.
  4. Variable naming: temp could be renamed to level or current_level for better readability.

VERDICT: PASS


Course Schedule (Problem 2- Leetcode207.py)

Great work! Your solution using Kahn's algorithm (BFS-based topological sort) is a clean and efficient alternative to DFS-based cycle detection. Here are some suggestions:

  1. Fix the time complexity comment: Change #Time Complexity: O(n) to #Time Complexity: O(V + E) or #Time Complexity: O(numCourses + len(prerequisites)) to accurately reflect the algorithm's complexity.

  2. Remove redundant check: The if not q: return False check is unnecessary because if the queue is empty, the while loop won't execute and the function will naturally return False at the end.

  3. Consider using a defaultdict: Instead of checking if pr[1] not in graph, you could use from collections import defaultdict and graph = defaultdict(list) for cleaner code.

  4. Good practices observed:

    • Proper use of deque for O(1) popleft operations
    • Early termination when all courses are processed
    • Clear variable naming and good code organization

VERDICT: PASS

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