{"record":{"id":"2e572171f7a48032","repo":"TheAlgorithms/Go","slug":"left-boundary-must-smaller-than-right","errorCode":null,"errorMessage":"left boundary must smaller than right","messagePattern":"left boundary must smaller than right","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"structure/linkedlist/singlylinkedlist.go","lineNumber":165,"sourceCode":"\ttmpNode := &Node[T]{}\n\ttmpNode.Next = ll.Head\n\tpre := tmpNode\n\tfor i := 0; i < left-1; i++ {\n\t\tpre = pre.Next\n\t}\n\tcur := pre.Next\n\tfor i := 0; i < right-left; i++ {\n\t\tnext := cur.Next\n\t\tcur.Next = next.Next\n\t\tnext.Next = pre.Next\n\t\tpre.Next = next\n\t}\n\tll.Head = tmpNode.Next\n\treturn nil\n}\nfunc (ll *Singly[T]) CheckRangeFromIndex(left, right int) error {\n\tif left > right {\n\t\treturn errors.New(\"left boundary must smaller than right\")\n\t} else if left < 1 {\n\t\treturn errors.New(\"left boundary starts from the first node\")\n\t} else if right > ll.length {\n\t\treturn errors.New(\"right boundary cannot be greater than the length of the linked list\")\n\t}\n\treturn nil\n}\n\n// Display prints out the elements of the list.\nfunc (ll *Singly[T]) Display() {\n\tfor cur := ll.Head; cur != nil; cur = cur.Next {\n\t\tfmt.Print(cur.Val, \" \")\n\t}\n\n\tfmt.Print(\"\\n\")\n}\n","sourceCodeStart":147,"sourceCodeEnd":182,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/structure/linkedlist/singlylinkedlist.go#L147-L182","documentation":"Singly.CheckRangeFromIndex validates the [left, right] partition bounds used by ReversePartition. This first check rejects ranges where left exceeds right, since such a range is empty or malformed and reversal would be undefined.","triggerScenarios":"Calling ReversePartition(left, right) with left > right — e.g. swapping arguments accidentally, or computing bounds from variables where the smaller/larger order was not normalized.","commonSituations":"User-supplied range input (start/end) not normalized; sorting two variables incorrectly; off-by-sign errors when indexes are derived from other data.","solutions":["Normalize bounds before calling: if left > right { left, right = right, left }","Validate the range in the caller and return a clearer domain error","Fix the argument order at the call site"],"exampleFix":"// before\nll.ReversePartition(right, left) // swapped\n// after\nif left > right {\n    left, right = right, left\n}\nll.ReversePartition(left, right)","handlingStrategy":"validation","validationCode":"if left > right {\n    left, right = right, left // normalize\n}\nll.ReversePartition(left, right)","typeGuard":null,"tryCatchPattern":"if err := ll.CheckRangeFromIndex(left, right); err != nil {\n    return fmt.Errorf(\"reverse partition [%d,%d]: %w\", left, right, err)\n}","preventionTips":["Normalize unordered bounds before calling","Keep a consistent argument order (low, high) across your API","Validate ranges at the boundary where user input enters"],"tags":["go","data-structures","linked-list","bounds-check","argument-validation"],"backgroundTag":"invalid-argument-range","analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}