def METHOD_NAME(groups, valid_keys_map) -> QuotaNode:
    root = QuotaNode("root", {})
    for group in groups:
        r = root
        paths = group["path"].split("/")[1:]
        # loop through all segements except the last segment
        # the last segment is the one we want to add the attributes to
        for segment in paths[0: len(paths) - 1]:
            for child in r.children:
                if child.name == segment:
                    r = child
                    break
            else:
                # no child found, add it with the segment name of the path
                n = QuotaNode(segment, {})
                r.addChild(n)
                r = n
        # add the child with it's attributes and last segment name
        n = QuotaNode(
            paths[len(paths) - 1],
            _filter_quota_attrs(group["attributes"], valid_keys_map)
        )
        r.addChild(n)
    return root