Skip to content

Bug Report for valid-tree #4283

Open
Open
@daniil-lyakhov

Description

@daniil-lyakhov

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]]
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions