{"record":{"id":"c46cef6df3bf221b","repo":"TheAlgorithms/Python","slug":"all-days-elements-should-be-greater-than-0","errorCode":null,"errorMessage":"All days elements should be greater than 0","messagePattern":"All days elements should be greater than 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/minimum_tickets_cost.py","lineNumber":102,"sourceCode":"\n    >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [1, 2, 3, 4])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n    \"\"\"\n\n    # Validation\n    if not isinstance(days, list) or not all(isinstance(day, int) for day in days):\n        raise ValueError(\"The parameter days should be a list of integers\")\n\n    if len(costs) != 3 or not all(isinstance(cost, int) for cost in costs):\n        raise ValueError(\"The parameter costs should be a list of three integers\")\n\n    if len(days) == 0:\n        return 0\n\n    if min(days) <= 0:\n        raise ValueError(\"All days elements should be greater than 0\")\n\n    if max(days) >= 366:\n        raise ValueError(\"All days elements should be less than 366\")\n\n    days_set = set(days)\n\n    @functools.cache\n    def dynamic_programming(index: int) -> int:\n        if index > 365:\n            return 0\n\n        if index not in days_set:\n            return dynamic_programming(index + 1)\n\n        return min(\n            costs[0] + dynamic_programming(index + 1),\n            costs[1] + dynamic_programming(index + 7),\n            costs[2] + dynamic_programming(index + 30),","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/minimum_tickets_cost.py#L84-L120","documentation":"Raised by mincost_tickets() when any travel day is <= 0. The algorithm indexes a DP over day numbers 1..365 (dynamic_programming(index) recurses up to 365 then stops), so days must be positive calendar days. Zero or negative values would corrupt the recursion bounds and are rejected after the empty-list check.","triggerScenarios":"Calling mincost_tickets([0, 5, 10], [2, 7, 15]), or with negative days such as mincost_tickets([-3, 40], [2, 7, 15]). Only triggers when days is non-empty, since len(days) == 0 returns 0 first.","commonSituations":"Using 0-based day offsets instead of 1-based calendar days (day 0 meaning 'today'); off-by-one bugs when computing day numbers from timestamps; feeding parsed dates that failed and defaulted to 0.","solutions":["Convert 0-based day offsets to 1-based by adding 1: days = [d + 1 for d in days].","Sanitize input dates before calling: reject or remap any day <= 0.","If days represent elapsed days from a start date, recompute them as actual calendar day numbers (1..365)."],"exampleFix":"# before\nmincost_tickets([0, 3, 7], [2, 7, 15])  # ValueError\n\n# after\nmincost_tickets([1, 4, 8], [2, 7, 15])","handlingStrategy":"validation","validationCode":"def valid_days(days: list[int]) -> bool:\n    return all(isinstance(d, int) and 1 <= d <= 365 for d in days)","typeGuard":"def is_valid_day_list(days: object) -> TypeGuard[list[int]]:\n    return isinstance(days, list) and all(\n        type(d) is int and 1 <= d <= 365 for d in days\n    )","tryCatchPattern":"try:\n    mincost_tickets(days, costs)\nexcept ValueError as e:\n    if 'greater than 0' in str(e):\n        days = [d + 1 for d in days]  # fix 0-based offsets\n    else:\n        raise","preventionTips":["Use 1-based calendar day numbers (datetime.timetuple().tm_yday gives these).","Add +1 when converting from 0-based offsets.","Validate the day range where the data enters your program, not at the algorithm call."],"tags":["dynamic-programming","input-validation","off-by-one"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}