{"record":{"id":"9074546d21219f09","repo":"donnemartin/interactive-coding-challenges","slug":"array-cannot-be-none-907454","errorCode":null,"errorMessage":"array cannot be None","messagePattern":"array cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/prod_three/prod_three_solution.ipynb","lineNumber":155,"sourceCode":"  },\n  {\n   \"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\",","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/prod_three/prod_three_solution.ipynb#L137-L173","documentation":"Raised by Solution.max_prod_three_nlogn when array is None. The O(n log n) approach sorts the array in place and multiplies the last three elements, so a None input is rejected with TypeError before sorting would fail.","triggerScenarios":"Calling max_prod_three_nlogn(None) or max_prod_three_nlogn() with an uninitialized variable.","commonSituations":"Optional numeric datasets (empty feed, missing column) flowing into the routine; also beware it mutates the caller's list via array.sort().","solutions":["Coalesce None to [] (then the length guard gives a clear ValueError) or filter the data source.","Check array is not None at the call site.","Pass sorted(array) or a copy if mutation of the original matters."],"exampleFix":"# before\nSolution().max_prod_three_nlogn(values)  # values may be None\n\n# after\nSolution().max_prod_three_nlogn(values or [])","handlingStrategy":"type-guard","validationCode":"if not array:\n    array = []\nbest = Solution().max_prod_three_nlogn(array) if array else None","typeGuard":"def is_int_list(x):\n    return isinstance(x, list) and all(isinstance(v, int) for v in x)","tryCatchPattern":"try:\n    Solution().max_prod_three_nlogn(array)\nexcept TypeError as e:\n    if 'cannot be None' in str(e):\n        array = []\n    else:\n        raise","preventionTips":["Coalesce None inputs to [] before calling.","Note the method sorts in place; pass a copy if the original order matters."],"tags":["python","null-check","in-place-sort","typeerror"],"backgroundTag":"none-argument-guard","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}