{"record":{"id":"c5e1229acccf66fc","repo":"donnemartin/interactive-coding-challenges","slug":"array-must-have-3-or-more-ints","errorCode":null,"errorMessage":"array must have 3 or more ints","messagePattern":"array must have 3 or more ints","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"online_judges/prod_three/prod_three_solution.ipynb","lineNumber":157,"sourceCode":"   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Code\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def max_prod_three_nlogn(self, array):\\n\",\n    \"        if array is None:\\n\",\n    \"            raise TypeError('array cannot be None')\\n\",\n    \"        if len(array) < 3:\\n\",\n    \"            raise ValueError('array must have 3 or more ints')\\n\",\n    \"        array.sort()\\n\",\n    \"        product = 1\\n\",\n    \"        for item in array[-3:]:\\n\",\n    \"            product *= item\\n\",\n    \"        return product\\n\",\n    \"\\n\",\n    \"    def max_prod_three(self, array):\\n\",\n    \"        if array is None:\\n\",\n    \"            raise TypeError('array cannot be None')\\n\",\n    \"        if len(array) < 3:\\n\",\n    \"            raise ValueError('array must have 3 or more ints')\\n\",\n    \"        curr_max_prod_three = array[0] * array[1] * array[2]\\n\",\n    \"        max_prod_two = array[0] * array[1]\\n\",\n    \"        min_prod_two = array[0] * array[1]\\n\",\n    \"        max_num = max(array[0], array[1])\\n\",\n    \"        min_num = min(array[0], array[1])\\n\",\n    \"        for i in range(2, len(array)):\\n\",\n    \"            curr_max_prod_three = max(curr_max_prod_three,\\n\",","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/prod_three/prod_three_solution.ipynb#L139-L175","documentation":"Raised by Solution.max_prod_three_nlogn when the array has fewer than 3 elements. The maximum product of three numbers is undefined without at least three values, so the method raises ValueError('array must have 3 or more ints') before sorting.","triggerScenarios":"Calling max_prod_three_nlogn([1, 2]) or with an empty list.","commonSituations":"Small or filtered-down datasets (e.g. filtering outliers leaves 2 items); test edge cases with short arrays.","solutions":["Check len(array) >= 3 before calling and skip/handle short inputs.","Catch ValueError at the call site and treat it as 'insufficient data'.","Fix the data pipeline so it guarantees at least three samples."],"exampleFix":"# before\nbest = Solution().max_prod_three_nlogn([1, 2])  # ValueError\n\n# after\nnums = [1, 2]\nbest = Solution().max_prod_three_nlogn(nums) if len(nums) >= 3 else None","handlingStrategy":"validation","validationCode":"if len(array) >= 3:\n    best = Solution().max_prod_three_nlogn(array)\nelse:\n    best = None  # insufficient data","typeGuard":"def has_three_ints(x):\n    return isinstance(x, list) and len(x) >= 3 and all(isinstance(v, int) for v in x)","tryCatchPattern":"try:\n    best = Solution().max_prod_three_nlogn(array)\nexcept ValueError as e:\n    if '3 or more' in str(e):\n        best = None\n    else:\n        raise","preventionTips":["Length-check inputs before product-of-three routines.","Log short datasets instead of letting guards throw in pipelines."],"tags":["python","input-validation","algorithm","valueerror"],"backgroundTag":"invalid-input-length","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}