Conversation
Find the town Judge (Problem1.py)Your solution is excellent and matches the reference solution in both approach and complexity. You have correctly handled the indegree counting by decrementing for the trust giver and incrementing for the trust receiver. The edge case for n=1 is appropriately handled. The code is well-structured and readable with clear comments. One minor improvement: Instead of iterating over the indices of the trust list with Also, note that the indegrees array is of length n+1, and you are iterating from index 0 to n. However, since person labels start from 1, the first element (index 0) is unused. Your loop for finding the judge starts from index 0, which is acceptable because index 0 will never have n-1 (since n>=1 and indegrees[0] is initialized to 0). But it's slightly inefficient to check index 0. You can start the loop from 1 to n: Here's the slightly optimized version: class Solution:
def findJudge(self, n: int, trust: List[List[int]]) -> int:
indegrees = [0] * (n+1)
for tr in trust:
indegrees[tr[0]] -= 1
indegrees[tr[1]] += 1
for i in range(1, n+1):
if indegrees[i] == n-1:
return i
return -1Overall, great job! VERDICT: PASS Ball in the Maze (Problem2.py)Strengths:
Areas for Improvement:
Recommendation:
VERDICT: NEEDS_IMPROVEMENT |
No description provided.