{"id":"code-col-explain-list-vs-set-membership","audience":"college","category":"coding","track":"coding","technique":"format","title":"Explain the Big-O cost of checking a list vs a set","free":false,"task":"Your teammate asks why the dedupe script is slow. Explain in exactly 3 numbered lines labeled 'Now:', 'With a set:' and 'Trade-off:', each under 25 words. 'Now:' gives the current Big-O and why, 'With a set:' gives the Big-O with a set and why, and 'Trade-off:' names one thing a set loses compared to the list. No code blocks, don't rewrite the code, under 80 words.","materialLabel":"The script and the teammate's question (attached to your prompt automatically)","material":"# dedupe_emails.py  (Python 3.12) - our Hackathon sign-up export cleaner\n\ndef dedupe(emails):\n    seen = []\n    result = []\n    for e in emails:\n        key = e.strip().lower()\n        if key not in seen:\n            seen.append(key)\n            result.append(e)\n    return result\n\n\n# Teammate (Jordan) in our group chat:\n# \"dedupe() took 0.2s on the test file (1,000 emails) but 3 minutes on\n#  the real export (90,000). Why does 90x more data take 900x longer??\n#  Should I just buy a bigger laptop lol\"\n#\n# Facts:\n#  - n = number of emails\n#  - result must keep the first copy of each email, in the original order\n#  - Python's `x in some_list` checks items one by one\n#  - Python's `x in some_set` uses hashing (about constant time)\n#\n# I want to explain it to Jordan so they can make the change themselves.","rules":[{"type":"numberedItems","count":3},{"type":"codeBlocks","count":0},{"type":"maxProseWords","max":80}],"mistakes":[{"title":"A lecture on Big-O","why":"The AI explains complexity theory instead of answering Jordan.","fix":"Say: \"Exactly 3 numbered lines, each under 25 words.\"","checks":["numberedItems","maxProseWords"]},{"title":"No labels","why":"Without labels, the before, after and catch get mixed together.","fix":"Give them: \"Now:, With a set:, Trade-off:\".","checks":["r0","r1"]},{"title":"Skipping the catch","why":"The AI says 'use a set' without mentioning what a set doesn't keep.","fix":"Add: \"Trade-off: one thing a set loses compared to the list.\"","checks":["r2"]},{"title":"Rewriting the code","why":"The AI pastes the fixed function, but Jordan wants to make the change.","fix":"Add: \"No code blocks; don't rewrite it.\"","checks":["codeBlocks","r2"]}],"promptHints":[{"label":"Gives the labels","patterns":["now:","with a set","trade.?off"]},{"label":"Asks for Big-O","patterns":["big.?o","O\\(n"]},{"label":"Sets the number of lines","patterns":["\\b(3|three)\\b.{0,15}line","numbered"]},{"label":"Rules out code","patterns":["no code","don'?t rewrite"]},{"label":"Caps each line","patterns":["\\d+\\s*words"]}],"hint":"Jordan needs the cost now, the cost after, and the catch. Ask for exactly those three labeled lines and no rewrite.","rubricLabels":["Line 1 starts with 'Now:' and says O(n^2) because 'key not in seen' scans the growing list for every email","Line 2 starts with 'With a set:' and says O(n) because set membership checks are about constant time","Line 3 starts with 'Trade-off:' and names one real loss, such as a set not keeping order (so result must stay a list) or using more memory, and no code is given"]}