{"record":{"id":"ade3f6c023f07402","repo":"donnemartin/interactive-coding-challenges","slug":"prices-cannot-be-none","errorCode":null,"errorMessage":"prices cannot be None","messagePattern":"prices cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/max_profit/max_profit_solution.ipynb","lineNumber":103,"sourceCode":"   \"metadata\": {},\n   \"source\": [\n    \"## Code\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"import sys\\n\",\n    \"\\n\",\n    \"\\n\",\n    \"class Solution(object):\\n\",\n    \"\\n\",\n    \"    def find_max_profit(self, prices):\\n\",\n    \"        if prices is None:\\n\",\n    \"            raise TypeError('prices cannot be None')\\n\",\n    \"        if len(prices) < 2:\\n\",\n    \"            raise ValueError('prices must have at least two values')\\n\",\n    \"        min_price = prices.pop(0)\\n\",\n    \"        max_profit = prices[0] - min_price\\n\",\n    \"        for price in prices:\\n\",\n    \"            profit = price - min_price\\n\",\n    \"            min_price = min(price, min_price)\\n\",\n    \"            max_profit = max(profit, max_profit)\\n\",\n    \"        return max_profit\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Unit Test\"\n   ]\n  },","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/max_profit/max_profit_solution.ipynb#L85-L121","documentation":"Raised by Solution.find_max_profit when prices is None. The method calls len(prices) and pops from it, which would fail on None; the guard requires a list of prices. Note a list with fewer than 2 values is a separate ValueError.","triggerScenarios":"Calling find_max_profit(None) — e.g. a market-data fetch returned None on error, or the prices variable was never populated before the call.","commonSituations":"API/DB fetchers that return None instead of [] on failure or empty results; tests of the guards; notebook cells run out of order.","solutions":["Pass a list with at least two prices","Make your data loader return [] (and handle it) rather than None","Guard: if prices: solution.find_max_profit(prices)"],"exampleFix":"# before\nprices = fetch_prices(symbol)  # returns None on API error\nsolution.find_max_profit(prices)\n\n# after\nprices = fetch_prices(symbol)\nif prices is None:\n    prices = []\nif len(prices) >= 2:\n    solution.find_max_profit(prices)","handlingStrategy":"validation","validationCode":"prices = prices or []\nif len(prices) >= 2: solution.find_max_profit(prices)","typeGuard":"def is_price_list(x): return isinstance(x, list) and len(x) >= 2","tryCatchPattern":"try:\n    p = solution.find_max_profit(prices)\nexcept (TypeError, ValueError) as e:\n    p = 0\n    logger.warning(e)","preventionTips":["Make market-data fetchers return [] on failure","Check both None and length >= 2 before calling"],"tags":["python","input-validation","none-check","arrays","greedy"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}