{"record":{"id":"f397d3bb41b281b3","repo":"donnemartin/interactive-coding-challenges","slug":"greed-indices-or-cookie-sizes-cannot-be-none","errorCode":null,"errorMessage":"greed_indices or cookie_sizes cannot be None","messagePattern":"greed_indices or cookie_sizes cannot be None","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"online_judges/assign_cookies/assign_cookies_solution.ipynb","lineNumber":128,"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 find_content_children(self, greed_indices, cookie_sizes):\\n\",\n    \"        if greed_indices is None or cookie_sizes is None:\\n\",\n    \"            raise TypeError('greed_indices or cookie_sizes cannot be None')\\n\",\n    \"        if not greed_indices or not cookie_sizes:\\n\",\n    \"            return 0\\n\",\n    \"        greed_indices.sort()\\n\",\n    \"        cookie_sizes.sort()\\n\",\n    \"        greed_index = 0\\n\",\n    \"        num_children = 0\\n\",\n    \"        for size in cookie_sizes:\\n\",\n    \"            if greed_index >= len(greed_indices):\\n\",\n    \"                break\\n\",\n    \"            if size >= greed_indices[greed_index]:\\n\",\n    \"                num_children += 1\\n\",\n    \"                greed_index += 1\\n\",\n    \"        return num_children\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/donnemartin/interactive-coding-challenges/blob/358f2cc60426d5c4c3d7d580910eec9a7b393fa9/online_judges/assign_cookies/assign_cookies_solution.ipynb#L110-L146","documentation":"Raised by Solution.find_content_children (LeetCode 'Assign Cookies') when greed_indices or cookie_sizes is None. Both lists are sorted and iterated, so None would crash with a confusing AttributeError; the guard makes the list contract explicit.","triggerScenarios":"Calling find_content_children(None, [1,2]) or with either list None — often from an optional argument, an empty initialization like greed = None, or a missing dict key.","commonSituations":"Test cases asserting the None guard; adapters receiving possibly-missing arrays from JSON payloads.","solutions":["Pass two lists (possibly empty — empty lists correctly return 0)","Initialize variables to [] instead of None","Check for None and default to empty list before the call"],"exampleFix":"# before\nsolution.find_content_children(payload.get('g'), payload.get('s'))\n\n# after\nsolution.find_content_children(payload.get('g') or [], payload.get('s') or [])","handlingStrategy":"validation","validationCode":"greed_indices = greed_indices or []\ncookie_sizes = cookie_sizes or []\nsolution.find_content_children(greed_indices, cookie_sizes)","typeGuard":"def is_list(x): return isinstance(x, list)","tryCatchPattern":"try:\n    n = solution.find_content_children(g, s)\nexcept TypeError:\n    n = 0","preventionTips":["Initialize list variables to [] not None","Use `or []` when arrays come from nullable payloads"],"tags":["python","input-validation","none-check","greedy","arrays"],"backgroundTag":"none-argument-validation","analyzedSha":"358f2cc60426d5c4c3d7d580910eec9a7b393fa9","analyzedAt":"2026-08-28T10:16:54.480Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}