{"record":{"id":"9a646d15d47ad0c6","repo":"TheAlgorithms/C-Sharp","slug":"the-parameter-s-value-is-invalid","errorCode":null,"errorMessage":"The parameter's value is invalid.","messagePattern":"The parameter's value is invalid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"DataStructures/ScapegoatTree/Extensions.cs","lineNumber":41,"sourceCode":"        }\n    }\n\n    /// <summary>\n    /// Rebuilds a scapegoat tree from list of nodes.\n    /// Use with <see cref=\"FlattenTree{TKey}\"/> method.\n    /// </summary>\n    /// <param name=\"list\">Flattened tree.</param>\n    /// <param name=\"start\">Start index.</param>\n    /// <param name=\"end\">End index.</param>\n    /// <typeparam name=\"TKey\">Scapegoat tree node key type.</typeparam>\n    /// <returns>Scapegoat tree root node.</returns>\n    /// <exception cref=\"ArgumentException\">Thrown if start index is invalid.</exception>\n    public static Node<TKey> RebuildFromList<TKey>(IList<Node<TKey>> list, int start, int end)\n        where TKey : IComparable\n    {\n        if (start > end)\n        {\n            throw new ArgumentException(\"The parameter's value is invalid.\", nameof(start));\n        }\n\n        var pivot = Convert.ToInt32(Math.Ceiling(start + (end - start) / 2.0));\n\n        return new Node<TKey>(list[pivot].Key)\n        {\n            Left = start > (pivot - 1) ? null : RebuildFromList(list, start, pivot - 1),\n            Right = (pivot + 1) > end ? null : RebuildFromList(list, pivot + 1, end),\n        };\n    }\n}\n","sourceCodeStart":23,"sourceCodeEnd":53,"githubUrl":"https://github.com/TheAlgorithms/C-Sharp/blob/96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c/DataStructures/ScapegoatTree/Extensions.cs#L23-L53","documentation":"RebuildFromList rebuilds a balanced subtree of scapegoat-tree nodes from a list slice delimited by [start, end]. It throws ArgumentException when start is greater than end, meaning the requested window is inverted and cannot define a subtree. The parameter named in the exception is `start`.","triggerScenarios":"Calling RebuildFromList with start > end, e.g. passing indexes in the wrong order or computing an empty/negative-length range.","commonSituations":"Off-by-one errors when slicing node lists after collecting an in-order path; passing (end, start) swapped; callers that computed an empty range (start == end+1) instead of handling it separately.","solutions":["Ensure start <= end before calling RebuildFromList; swap or normalize the indexes if needed.","Decide explicitly how an empty range should behave (return null or skip the rebuild) and guard before calling.","Validate computed indexes against the list bounds as well (0 <= start, end < list.Count)."],"exampleFix":"// before\nvar node = Node<TKey>.RebuildFromList(nodes, end, start);\n// after\nif (start > end) (start, end) = (end, start);\nvar node = Node<TKey>.RebuildFromList(nodes, start, end);","handlingStrategy":"validation","validationCode":"if (list is null || start < 0 || end >= list.Count || start > end) throw new ArgumentOutOfRangeException(nameof(start), \"Require 0 <= start <= end < list.Count\");","typeGuard":"static bool IsValidRange<T>(int start, int end) => start <= end;","tryCatchPattern":null,"preventionTips":["Always normalize (min,max) before slicing node lists.","Add an assert start <= end near range computation.","Unit-test empty-range edge cases in tree rebuild helpers."],"tags":["argument-validation","data-structures","trees"],"backgroundTag":"invalid-argument-value","analyzedSha":"96e2905cab7bc6b33ac0a34ee5bb82ddccbcbb6c","analyzedAt":"2026-09-13T17:04:01.438Z","contentChangedAt":"2026-09-13T17:04:01.438Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}