{"record":{"id":"c2e903c6d07b176d","repo":"TheAlgorithms/Python","slug":"the-parameter-idx-original-string-must-not-be-lowe","errorCode":null,"errorMessage":"The parameter idx_original_string must not be lower than 0.","messagePattern":"The parameter idx_original_string must not be lower than 0\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"data_compression/burrows_wheeler.py","lineNumber":151,"sourceCode":"    len(bwt_string).\n    >>> reverse_bwt(\"mnpbnnaaaaaa\", 11.0)\n    'panamabanana'\n    >>> reverse_bwt(\"mnpbnnaaaaaa\", 11.4)\n    'panamabanana'\n    \"\"\"\n    if not isinstance(bwt_string, str):\n        raise TypeError(\"The parameter bwt_string type must be str.\")\n    if not bwt_string:\n        raise ValueError(\"The parameter bwt_string must not be empty.\")\n    try:\n        idx_original_string = int(idx_original_string)\n    except ValueError:\n        raise TypeError(\n            \"The parameter idx_original_string type must be int or passive\"\n            \" of cast to int.\"\n        )\n    if idx_original_string < 0:\n        raise ValueError(\"The parameter idx_original_string must not be lower than 0.\")\n    if idx_original_string >= len(bwt_string):\n        raise ValueError(\n            \"The parameter idx_original_string must be lower than len(bwt_string).\"\n        )\n\n    ordered_rotations = [\"\"] * len(bwt_string)\n    for _ in range(len(bwt_string)):\n        for i in range(len(bwt_string)):\n            ordered_rotations[i] = bwt_string[i] + ordered_rotations[i]\n        ordered_rotations.sort()\n    return ordered_rotations[idx_original_string]\n\n\nif __name__ == \"__main__\":\n    entry_msg = \"Provide a string that I will generate its BWT transform: \"\n    s = input(entry_msg).strip()\n    result = bwt_transform(s)\n    print(","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/data_compression/burrows_wheeler.py#L133-L169","documentation":"Raised by reverse_bwt() in data_compression/burrows_wheeler.py when idx_original_string (after int() coercion) is negative. A negative index cannot refer to any position in the ordered rotations list, so it is rejected before the upper-bound check.","triggerScenarios":"Calling reverse_bwt('mnpbnnaaaaaa', -1), or passing -0.5 (int(-0.5) == 0, so this does NOT raise), or a negative value from arithmetic such as idx = found - offset that underflows.","commonSituations":"Index arithmetic bugs (subtracting instead of adding), reading a signed field from a binary format where a corrupted sign bit yields a negative number, or unit tests probing boundary conditions.","solutions":["Clamp or validate the index before calling: if idx < 0: handle error; else call.","Trace where the negative index is computed — usually an off-by-sign arithmetic bug upstream.","If the value comes from untrusted data, validate the integer range at the parse boundary."],"exampleFix":"# before\nplain = reverse_bwt(bwt_str, idx)  # idx == -1\n\n# after\nif idx < 0:\n    raise ValueError(f'bad index {idx}')\nplain = reverse_bwt(bwt_str, idx)","handlingStrategy":"validation","validationCode":"if int(idx_original_string) < 0:\n    raise ValueError(f'negative index {idx_original_string}')\nplain = reverse_bwt(bwt_string, idx_original_string)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate integer fields as non-negative at parse time","Review index arithmetic for sign bugs"],"tags":["value-validation","burrows-wheeler","index","compression"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}