{"record":{"id":"1b8c0086804779f8","repo":"TheAlgorithms/Go","slug":"left-boundary-starts-from-the-first-node","errorCode":null,"errorMessage":"left boundary starts from the first node","messagePattern":"left boundary starts from the first node","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"structure/linkedlist/singlylinkedlist.go","lineNumber":167,"sourceCode":"\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":149,"sourceCodeEnd":182,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/structure/linkedlist/singlylinkedlist.go#L149-L182","documentation":"Singly.CheckRangeFromIndex enforces that positions are 1-based node positions, matching ReversePartition's convention that the first node is position 1. A left of 0 or negative would corrupt the traversal (e.g. seeking to a node before the head), so it is rejected with this error.","triggerScenarios":"Calling ReversePartition(left, right) with left < 1 — typically passing a 0-based index into this 1-based API, or a computed offset that went negative.","commonSituations":"Mixing 0-based array indexing habits with this 1-based list API; subtracting from a position without a floor check; deserialized positions starting at 0.","solutions":["Convert 0-based indexes to 1-based by adding 1 before the call","Clamp: if left < 1 { left = 1 }","Validate user input so positions are at least 1"],"exampleFix":"// before\nll.ReversePartition(i, j) // i, j are 0-based\n// after\nll.ReversePartition(i+1, j+1) // convert to 1-based node positions","handlingStrategy":"validation","validationCode":"if left < 1 {\n    return errors.New(\"positions are 1-based; left must be >= 1\")\n}\nll.ReversePartition(left, right)","typeGuard":null,"tryCatchPattern":"if err := ll.CheckRangeFromIndex(left, right); err != nil {\n    return fmt.Errorf(\"invalid range: %w\", err)\n}","preventionTips":["Remember this API is 1-based; convert 0-based indexes (+1)","Clamp computed positions to a minimum of 1","Document the 1-based convention where positions originate"],"tags":["go","data-structures","linked-list","bounds-check","off-by-one"],"backgroundTag":"invalid-argument-range","analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}