Open
Description
Bug Report for https://neetcode.io/problems/valid-tree
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
A wrong solution is being accepted:
class Solution:
def validTree(self, n: int, edges: List[List[int]]) -> bool:
data = [i for i in range(n)]
for i, j in edges:
root = min(i, j, data[i], data[j])
data[i] = data[j] = root
return all(data[0] == x for x in data[1:]) and len(edges) == n-1
Fix:
Test case
n=5
edges=[[4,3],[3,2],[2,1],[1,0]]

Metadata
Metadata
Assignees
Labels
No labels