{"id":"last-stone-weight","title":"Last Stone Weight","difficulty":"easy","patterns":["heap"],"primaryConcept":"heap-top-k","concepts":["heap-top-k"],"problemForm":"intro","companies":["Amazon","Google","Meta","Microsoft"],"category":"stacks-queues","executionStyle":"solution-method","compareMode":"exact","description":"You are given a list of stone weights. Repeatedly choose the two heaviest stones and smash them together.\n\nRules:\n- If the two stones have the same weight, both are destroyed.\n- If they have different weights, the heavier stone is replaced by the difference between the two weights.\n\nReturn the weight of the last remaining stone, or 0 if no stones remain.","examples":[{"input":"stones = [2,7,4,1,8,1]","output":"1","explanation":"Smash 8 and 7 to make 1, then continue until one stone of weight 1 remains."},{"input":"stones = [1]","output":"1","explanation":"There is only one stone, so it is already the answer."},{"input":"stones = [2,2]","output":"0","explanation":"The two stones have equal weight, so both are destroyed."}],"constraints":[{"id":"1-len-stones-30","text":"1 <= len(stones) <= 30","check":{"kind":"sizeRange","target":"stones","measure":"arrayLength","min":1,"max":30}},{"id":"1-stones-i-1000","text":"1 <= stones[i] <= 1000","check":{"kind":"valueRange","target":"stones","selector":"arrayItems","min":1,"max":1000}}],"starterCode":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        # Your code here\n        pass","functionName":"lastStoneWeight","testCases":[{"id":"1","input":{"stones":[2,7,4,1,8,1]},"expected":1,"description":"Canonical heap simulation."},{"id":"2","input":{"stones":[1]},"expected":1,"description":"Single stone."},{"id":"3","input":{"stones":[2,2]},"expected":0,"description":"Equal pair destroys both stones."},{"id":"4","input":{"stones":[10,4,2,10]},"expected":2,"description":"Largest pair cancels before smaller stones remain."},{"id":"5","input":{"stones":[9,3,2,10,8]},"expected":2,"description":"Several unequal smashes."},{"id":"h1","input":{"stones":[1,3]},"expected":2,"description":"Two unequal stones."},{"id":"h2","input":{"stones":[3,7,8]},"expected":2,"description":"A remainder later becomes the heaviest stone."},{"id":"h3","input":{"stones":[31,26,33,21,40]},"expected":9,"description":"Multiple rounds with changing maximums."},{"id":"h4","input":{"stones":[10,10,10]},"expected":10,"description":"A tie can leave a stone that still participates later."},{"id":"h5","input":{"stones":[1,3,3,5,7]},"expected":1,"description":"Several smaller ties can collapse into a final remainder."}],"hints":[{"level":1,"content":"Each round needs quick access to the current two heaviest stones.","revealPattern":false},{"level":2,"content":"Use a max-priority structure, or store negative weights in a min-heap.","revealPattern":true},{"level":3,"content":"Pop two weights, then push back the difference only when the weights are not equal.","revealPattern":true}],"guidedFlow":{"version":2,"progressRevision":"last-stone-weight-2026-07-19-active-heap-state","approachSelection":{"contract":"approach-selection-v1","question":"Which structure handles repeated heaviest-value removals?","decisionPrompt":"A new stone can re-enter after every smash, so weigh how each option pays for that.","approaches":[{"id":"sort-every-round","name":"Re-sort every round","summary":"Sort the whole list, take the last two, smash them, append the difference, and sort again next round.","decisionReason":"It gets the right answer, but re-sorting the full list each round redoes almost all the ordering the previous sort already produced.","complexity":{"time":"O(n^2 log n)","space":"O(n)"},"tradeoffs":["Up to n rounds, each paying a full O(n log n) sort."],"isOptimal":false},{"id":"heap-simulation","name":"Keep the stones in a heap","summary":"Hold every stone in a max-priority heap, pop the two heaviest each round, and push the positive difference back.","decisionReason":"A heap surrenders its largest element and absorbs a new one in log time, so a round costs O(log n) instead of a fresh sort.","complexity":{"time":"O(n log n)","space":"O(n)"},"tradeoffs":["Each pop or push touches one root-to-leaf path, never the whole list."],"isOptimal":true}]},"codingCheckpoints":[{"id":"init-heap","title":"Open one priority pool","description":"Before any smashing, create a single heap that will surrender its heaviest stone on demand.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"initializes_heap_storage","scope":"init-heap","readMode":"heap-value-query-v1"}]},"commonMistakes":["Keeping the stones in a plain list with no priority order","Rebuilding a new heap inside every round"],"hint":"One heap, created once, holds every stone still in play.","semanticSpec":{"intent":"Create the single priority heap that will hold all current stones before the simulation begins.","doneWhen":"This step is done when one empty heap container exists before the smash loop.","shouldFailWhen":"This step should fail if the storage is an unordered list, or a new heap is rebuilt each round.","roles":["heap container","created once","priority storage"],"mustProve":["A heap that can return its largest element exists before the loop.","The same heap is reused across every round."],"mustNotAccept":["Storing stones in a list with no priority behavior.","Allocating a fresh heap inside each smash round."],"proofSnippets":[{"id":"py-last-stone-init-heap","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []"}]}},{"id":"push-stones","title":"Load every stone in","description":"Place all the starting weights into the heap so the heaviest stone can be pulled out first.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"pushes_heap_values","scope":"heap-push","readMode":"heap-value-query-v1"}]},"commonMistakes":["Ordering the heap so the smallest weight surfaces first","Leaving the heap empty when the loop starts"],"hint":"Insert each weight so that the largest one sits at the top.","semanticSpec":{"intent":"Insert all input stone weights into the heap with the heaviest reachable at the top.","doneWhen":"This step is done when every starting weight is in the heap and the maximum is the next one out.","shouldFailWhen":"This step should fail if the smallest weight surfaces first, or some weights are never inserted.","roles":["bulk insertion","max reachable on top","all weights present"],"mustProve":["Every starting stone weight is added to the heap.","The ordering exposes the largest weight first."],"mustNotAccept":["Leaving the heap empty before the smash loop.","Arranging the heap so the smallest weight comes out first."],"proofSnippets":[{"id":"py-last-stone-push-stones","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)"}]}},{"id":"continue-while-pairs-remain","title":"Loop while two stones remain","description":"Keep smashing only while the heap still holds at least two stones to pick from.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"maintains_heap_size_bound","scope":"pair-loop","readMode":"heap-value-query-v1"}]},"commonMistakes":["Halting while two stones are still available","Entering the round body with only one stone left"],"hint":"Guard the round on the heap holding more than one stone.","semanticSpec":{"intent":"Run a round only when the heap contains two or more stones to smash together.","doneWhen":"This step is done when the loop continues for two-or-more stones and stops otherwise.","shouldFailWhen":"This step should fail if a round runs with fewer than two stones, or stops while two remain.","roles":["loop guard","two-or-more condition","round driver"],"mustProve":["Each round begins only when at least two stones are available.","The loop ends once fewer than two stones remain."],"mustNotAccept":["Running the round body with a single stone left.","Stopping the loop while two stones could still smash."],"proofSnippets":[{"id":"py-last-stone-continue-while-pairs-remain","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            pass"}]}},{"id":"pop-two-heaviest","title":"Pull out the two heaviest","description":"Each round removes the heaviest stone and then the next heaviest from the heap.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"extracts_heap_values","scope":"heap-pop","readMode":"heap-value-query-v1"}]},"commonMistakes":["Reading the top stone without removing it","Taking only one stone out per round"],"hint":"Remove from the top twice to get the two largest.","semanticSpec":{"intent":"Remove the two largest stones from the heap to be smashed together this round.","doneWhen":"This step is done when both the heaviest and second-heaviest are taken out of the heap.","shouldFailWhen":"This step should fail if a top stone is only peeked, or just one stone is removed.","roles":["two removals","largest then next-largest","taken off the heap"],"mustProve":["The heaviest stone is removed from the heap.","The next heaviest is also removed in the same round."],"mustNotAccept":["Inspecting the top stone without removing it.","Removing only one stone per round."],"proofSnippets":[{"id":"py-last-stone-pop-two-heaviest","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)"}]}},{"id":"push-remainder","title":"Return the leftover weight","description":"When the two stones differ, push their difference back so it can be smashed in a later round.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"reinserts_projected_heap_values","scope":"push-difference","readMode":"heap-value-query-v1"}]},"commonMistakes":["Pushing a difference of zero when the stones were equal","Dropping the leftover weight instead of returning it"],"hint":"A positive difference is a real stone and rejoins the heap.","semanticSpec":{"intent":"Insert the positive weight difference back into the heap when the two stones are unequal.","doneWhen":"This step is done when an unequal smash returns its difference and an equal smash returns nothing.","shouldFailWhen":"This step should fail if a zero difference is pushed, or a positive difference is lost.","roles":["conditional insertion","positive difference only","rejoins the heap"],"mustProve":["The positive difference of two unequal stones is pushed back.","Equal stones leave nothing behind to push."],"mustNotAccept":["Pushing a zero-weight stone after an equal smash.","Discarding the leftover difference of an unequal smash."],"proofSnippets":[{"id":"py-last-stone-push-remainder","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)\n            if x != y:\n                heapq.heappush(heap, -(y - x))"}]}},{"id":"return-last-stone","title":"Report the survivor","description":"After the loop, return the one remaining weight, or 0 when no stone is left.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"returns_heap_top","scope":"return-empty-zero","readMode":"heap-value-query-v1"}]},"commonMistakes":["Returning the heap itself instead of a weight","Reading the top when the heap is empty"],"hint":"One stone left is the answer; an empty heap means 0.","semanticSpec":{"intent":"Return the final stone weight when one remains, and 0 when the heap is empty.","doneWhen":"This step is done when a surviving weight is returned and an empty heap yields 0.","shouldFailWhen":"This step should fail if the heap object is returned, or an empty heap is read for a value.","roles":["final result","survivor weight","empty yields zero"],"mustProve":["A surviving stone weight is returned when the heap is non-empty.","An empty heap returns 0."],"mustNotAccept":["Returning the heap container instead of a weight.","Reading a value from an empty heap."],"proofSnippets":[{"id":"py-last-stone-return-last-stone","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)\n            if x != y:\n                heapq.heappush(heap, -(y - x))\n        if not heap:\n            return 0\n        return -heap[0]"}]}}],"slides":[{"id":"opener","chapter":"Understand","kind":"info","eyebrow":"Read the problem","title":"Smash the two heaviest stones until one is left","workspacePanel":"problem","body":["You have a pile of stone weights. Every round you take the two heaviest stones and smash them. Equal weights destroy each other; unequal weights leave a single stone whose weight is the difference, and that stone goes back with the rest.","Each round needs the two current heaviest stones, and a surviving difference returns to the same competition. The rest of the stones do not need a complete ordering."]},{"id":"brute-force","chapter":"The obvious way","kind":"code-trace","source":"brute-force","eyebrow":"Start naive","title":"Sort the stones, take the last two, repeat","summary":"Sort the whole list, smash the two stones at the end, drop the difference back in, and sort all over again. Watch how much re-sorting each round costs.","workspacePanel":"trace","codeTrace":{"contract":"code-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"while len(stones) > 1:\n    stones.sort()\n    y = stones.pop()\n    x = stones.pop()\n    if x != y:\n        stones.append(y - x)\nreturn stones[0] if stones else 0","steps":[{"id":"s1","title":"Sort, then smash 8 and 7","codeLine":2,"summary":"Sorting [2,7,4,1,8,1] gives [1,1,2,4,7,8]. The last two are 8 and 7; they differ by 1, so a stone of weight 1 drops back in.","state":{"nums":[1,1,2,4,7,8],"i":4,"j":5,"labels":{"nums":"stones","i":"x","j":"y"}}},{"id":"s2","title":"Sort again, smash 4 and 2","codeLine":2,"summary":"The set is now [1,1,1,2,4]. A full re-sort puts 4 and 2 at the end; their difference of 2 rejoins the pile.","state":{"nums":[1,1,1,2,4],"i":3,"j":4,"labels":{"nums":"stones","i":"x","j":"y"}}},{"id":"s3","title":"Sort once more, smash 2 and 1","codeLine":2,"summary":"Another full sort of [1,1,1,2] surfaces 2 and 1 at the end; their difference of 1 goes back, leaving three 1s.","state":{"nums":[1,1,1,2],"i":2,"j":3,"labels":{"nums":"stones","i":"x","j":"y"}}},{"id":"s4","title":"A final sort to find equal stones","codeLine":2,"summary":"Sorting [1,1,1] still costs a pass. The last two are both 1, so they cancel and the lone 1 is returned.","state":{"nums":[1,1,1],"i":1,"j":2,"labels":{"nums":"stones","i":"x","j":"y"}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"while (stones.length > 1) {\n    stones.sort((a, b) => a - b);\n    const y = stones.pop();\n    const x = stones.pop();\n    if (x !== y) {\n        stones.push((y - x));\n    }\n}\nreturn (stones.length > 0 ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":9},"statementBundles":{"6":{"startLine":6,"endLine":8}},"alternateStyles":{"close-to-source":{"code":"while (stones.length > 1) {\n    stones.sort((a, b) => a - b);\n    const poppedValue = stones.pop();\n    if (poppedValue === undefined) throw new Error(\"IndexError\");\n    const y = poppedValue;\n    const poppedValue2 = stones.pop();\n    if (poppedValue2 === undefined) throw new Error(\"IndexError\");\n    const x = poppedValue2;\n    if (x !== y) {\n        stones.push((y - x));\n    }\n}\nreturn (stones.length > 0 ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":6,"5":9,"6":10,"7":13},"statementBundles":{"3":{"startLine":3,"endLine":5},"4":{"startLine":6,"endLine":8},"6":{"startLine":10,"endLine":12}}}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"while (stones.length > 1) {\n    stones.sort((a, b) => a - b);\n    const y = stones.pop()!;\n    const x = stones.pop()!;\n    if (x !== y) {\n        stones.push((y - x));\n    }\n}\nreturn (stones.length > 0 ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":9},"statementBundles":{"6":{"startLine":6,"endLine":8}},"alternateStyles":{"close-to-source":{"code":"while (stones.length > 1) {\n    stones.sort((a, b) => a - b);\n    const poppedValue = stones.pop();\n    if (poppedValue === undefined) throw new Error(\"IndexError\");\n    const y = poppedValue;\n    const poppedValue2 = stones.pop();\n    if (poppedValue2 === undefined) throw new Error(\"IndexError\");\n    const x = poppedValue2;\n    if (x !== y) {\n        stones.push((y - x));\n    }\n}\nreturn (stones.length > 0 ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":6,"5":9,"6":10,"7":13},"statementBundles":{"3":{"startLine":3,"endLine":5},"4":{"startLine":6,"endLine":8},"6":{"startLine":10,"endLine":12}}}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"while (stones.size() > 1) {\n    Collections.sort(stones);\n    int y = stones.remove(stones.size() - 1);\n    int x = stones.remove(stones.size() - 1);\n    if (x != y) {\n        stones.add(y - x);\n    }\n}\nreturn (!stones.isEmpty() ? stones.get(0) : 0);","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":9},"statementBundles":{"6":{"startLine":6,"endLine":8}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"while (stones.Count > 1) {\n    stones.Sort();\n    int y = stones[stones.Count - 1];\n    stones.RemoveAt(stones.Count - 1);\n    int x = stones[stones.Count - 1];\n    stones.RemoveAt(stones.Count - 1);\n    if (x != y) {\n        stones.Add(y - x);\n    }\n}\nreturn (stones.Count > 0 ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":5,"5":7,"6":8,"7":11},"statementBundles":{"3":{"startLine":3,"endLine":4},"4":{"startLine":5,"endLine":6},"6":{"startLine":8,"endLine":10}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"while (stones.size() > 1) {\n    stable_sort(stones.begin(), stones.end());\n    int y = stones.back();\n    stones.pop_back();\n    int x = stones.back();\n    stones.pop_back();\n    if (x != y) {\n        stones.push_back((y - x));\n    }\n}\nreturn (!stones.empty() ? stones[0] : 0);","lineMap":{"1":1,"2":2,"3":3,"4":5,"5":7,"6":8,"7":11},"statementBundles":{"3":{"startLine":3,"endLine":4},"4":{"startLine":5,"endLine":6},"6":{"startLine":8,"endLine":10}}}}}},{"id":"cost-probe","chapter":"The obvious way","kind":"case-probe","eyebrow":"Count the cost","title":"What does sorting every round cost in total?","summary":"The trace keeps returning to the sort line after every smash. Decide whether that repeated ordering is cheap bookkeeping or the dominant work.","workspacePanel":"trace","options":[{"id":"n2-log-n","label":"About n rounds, each a full sort, so n^2 log n","rationale":"A smash removes one stone per round, so there can be close to n rounds, and each one re-sorts all the remaining stones at O(n log n).","isCorrect":true},{"id":"n-log-n","label":"One sort, so n log n overall","rationale":"A single sort would be n log n, but the pile changes every round and this plan sorts again each time rather than once.","isCorrect":false},{"id":"linear","label":"Linear, since each round touches one stone","rationale":"A round adds back at most one stone, but it still re-sorts the entire pile to find the top two, which is far more than linear.","isCorrect":false}],"answer":"About n^2 log n. Up to n rounds run, and each one throws away the previous ordering and sorts the whole pile again just to read off its two largest stones. That repeated sorting is the cost to beat."},{"id":"structure-probe","chapter":"The obvious way","kind":"case-probe","eyebrow":"Spot the waste","title":"What does each round actually need from your data?","summary":"After each smash, the pile changes and the next round has to choose from the updated weights.","workspacePanel":"visualizer","options":[{"id":"just-the-max","label":"Fast access to the current heaviest, even as stones leave and one rejoins","rationale":"A round pulls the top stone, then the next, then may insert a difference, and it never reads the stones below in order. It just needs the maximum handed over cheaply each time.","isCorrect":true},{"id":"full-order","label":"The whole pile kept in sorted order at all times","rationale":"Total order is exactly what the sort pays for and the round never uses; the stones below the top two are irrelevant until they rise.","isCorrect":false},{"id":"insertion-order","label":"The order the stones were originally given","rationale":"Stones are chosen by weight, not arrival, and a fresh difference can outweigh stones already present, so original order tells the round nothing.","isCorrect":false}],"answer":"A round only ever asks for the current heaviest, and it asks again and again as stones leave and a fresh difference drops in. A heap surrenders its maximum and absorbs a new value in log time, so it answers that question every round without sorting the rest.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"structure-top","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0,"highlighted":[1,2]}}}]}},{"id":"approach-selection","chapter":"The obvious way","kind":"choice","source":"approach-selection","eyebrow":"Pick the approach","title":"How should you keep the heaviest stone within reach?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"approach-heap","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0}}}]}},{"id":"heap-state-probe","chapter":"The obvious way","kind":"case-probe","eyebrow":"Define the state","title":"Before each smash, what must the heap contain?","summary":"The first smash removes 8 and 7 from stones = [2,7,4,1,8,1], then produces a new stone of weight 1.","workspacePanel":"visualizer","options":[{"id":"all-current-stones","label":"Every stone still alive, including any new difference, with the heaviest available first","rationale":"After 8 and 7 produce 1, the heap must hold 4, 2, 1, 1, 1. Keeping every current stone in the same heap makes 4 the next value removed.","isCorrect":true},{"id":"original-stones-only","label":"Only untouched original stones; keep each new difference outside","rationale":"The new weight 1 is a current stone and must compete in later rounds. Holding differences outside can choose the wrong pair once one of them becomes heavy enough."},{"id":"top-two-only","label":"Only the two stones selected for the next smash","rationale":"Discarding the rest loses weights that must return in later rounds. The heap stores the whole current pile while exposing its heaviest member first."}],"answer":"Before every round, the heap represents the complete current pile. After 8 and 7 smash, it holds 4, 2, 1, 1, 1, including the new difference, and exposes 4 as the next heaviest stone.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"heap-state-before-first-smash","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0}}}]}},{"id":"dry-run-setup","chapter":"Trace","kind":"info","eyebrow":"Watch it move","title":"All six stones sit in the heap, heaviest on top","workspacePanel":"visualizer","body":["Stones [2,7,4,1,8,1] settle into a heap with 8 at the root, so the two heaviest are the root and its larger child.","Each round pops those two, and an unequal smash creates a new weight whose placement decides what the next round reaches for."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"setup-heap","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0}}}]}},{"id":"trace","chapter":"Trace","kind":"dry-run","source":"trace-example","eyebrow":"Trace the smashes","title":"Collapse the heap to the final stone","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"smash-8-7","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0,"highlighted":[1]}}},{"id":"reinsert-2","state":{"heap":{"values":[4,2,1,1,1],"name":"heap","current":0,"highlighted":[1]}}},{"id":"equal-pair","state":{"heap":{"values":[1,1,1],"name":"heap","current":0,"highlighted":[1]}}}]},"beats":[{"id":"smash-8-7","title":"Which two stones smash first?","summary":"The heap holds 8, 7, 4, 2, 1, 1 with 8 at the root.","prompt":"Use the heap shape to decide which two values leave first.","options":[{"id":"eight-seven","label":"8 and 7, leaving a stone of weight 1","rationale":"The two heaviest are the root and its larger child, 8 and 7; they differ by 1, so a weight-1 stone drops back into the heap.","isCorrect":true},{"id":"eight-four","label":"8 and 4","rationale":"4 is a child of the root but not the second largest; 7 outweighs it, so 7 is the second stone pulled.","isCorrect":false},{"id":"two-ones","label":"The two stones of weight 1","rationale":"A round always takes the heaviest pair, and the lightest stones never lead off a round while heavier ones remain.","isCorrect":false}],"answer":"Smash 8 and 7. They differ by 1, so a stone of weight 1 rejoins the heap, which now holds 4, 2, 1, 1, 1."},{"id":"reinsert-2","title":"After smashing 4 and 2, what happens to the leftover 2?","summary":"The heap is now 4, 2, 1, 1, 1, and the top pair is 4 and 2.","prompt":"4 and 2 differ by 2.","options":[{"id":"rejoins","label":"It rejoins the heap and competes with the stones already there","rationale":"A positive difference is a real stone, so the weight-2 leftover sinks back in and is now tied for heaviest with nothing above it.","isCorrect":true},{"id":"set-aside","label":"It is set aside and added back only at the very end","rationale":"Holding it out would let a lighter stone smash out of turn; the difference has to compete immediately, the same as any other stone.","isCorrect":false},{"id":"discarded","label":"It is discarded, since the heavier stone was consumed","rationale":"Dropping it loses a real stone that still has weight, which would change the final answer.","isCorrect":false}],"answer":"The weight-2 leftover goes straight back into the heap, which becomes 2, 1, 1, 1."},{"id":"equal-pair","title":"Two equal stones meet at the top: what is left?","summary":"The heap has shrunk to 1, 1, 1, so the top pair are both weight 1.","prompt":"The two heaviest stones now weigh the same.","options":[{"id":"both-gone","label":"Both are destroyed and one stone of weight 1 is left","rationale":"Equal weights cancel completely, so nothing rejoins the heap and only the third 1 remains.","isCorrect":true},{"id":"push-zero","label":"A stone of weight 0 is pushed back","rationale":"Equal stones leave no leftover, so pushing a zero would invent a phantom stone the rules never produce.","isCorrect":false},{"id":"keep-one","label":"One of the two survives unchanged","rationale":"A smash never leaves a full stone behind; equal stones destroy each other entirely.","isCorrect":false}],"answer":"Both 1s are destroyed and nothing is pushed back, so a single stone of weight 1 is left. With fewer than two stones the loop stops and that survivor, weight 1, is the answer."}]},{"id":"drop-remainder-pitfall","chapter":"Trace","kind":"pitfall","eyebrow":"Spot the trap","title":"Could a plain heap pick the right pair?","summary":"A heap built straight from the weights is tempting: push every stone, pop two, smash, repeat. The structure and the loop look right, but the first two pops decide the whole simulation. Watch which pair it reaches for.","workspacePanel":"trace","pitfall":"The heap below is built straight from the raw weights, so its top is the lightest stone. Each round pops the two lightest instead of the two heaviest.","whyItMatters":"Last Stone Weight always smashes the two heaviest, but a plain heap surfaces its minimum. Negate each weight going in and coming out, so the heaviest stone sits at the top and is the first one popped.","negativeTrace":{"contract":"negative-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"import heapq\nheap: list[int] = []\nfor stone in stones:\n    heapq.heappush(heap, stone)\nwhile len(heap) > 1:\n    x = heapq.heappop(heap)\n    y = heapq.heappop(heap)\n    if x != y:\n        heapq.heappush(heap, y - x)\nif not heap:\n    return 0\nreturn heap[0]","steps":[{"id":"pf-build","title":"Build a heap from 3, 7, 8","summary":"For stones [3,7,8] the answer should be 2: the two heaviest, 8 and 7, smash to 1, then 3 and 1 smash to 2. But a plain heap floats the lightest stone, 3, up to the top.","codeLine":4,"state":{"heap":{"values":[3,7,8],"name":"heap","current":0,"highlighted":[1,2]}}},{"id":"pf-pop-light","title":"It pops 3 and 7, not 8 and 7","summary":"The two smallest come off the top: 3 then 7. They differ by 4, so a stone of weight 4 will be pushed back while the real heaviest, 8, was never touched.","codeLine":7,"state":{"heap":{"values":[8],"name":"heap","current":0}}},{"id":"pf-push-wrong","title":"A weight-4 stone rejoins","summary":"Pushing 4 leaves the heap holding 4 and 8, with 4 on top. The wrong pair smashed, so the leftover is wrong too.","codeLine":9,"state":{"heap":{"values":[4,8],"name":"heap","current":0,"highlighted":[1]}}},{"id":"pf-wrong","title":"It returns 4 instead of 2","summary":"The last round pops 4 and 8, they differ by 4, and 4 is pushed, leaving a single stone of weight 4. The function returns 4, but smashing the heaviest pair first gives 2.","codeLine":12,"state":{"heap":{"values":[4],"name":"heap","current":0}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"const heap = new MinHeap();\nfor (const stone of stones) {\n    heap.push(stone);\n}\nwhile (heap.size() > 1) {\n    const x = heap.pop();\n    const y = heap.pop();\n    if (x !== y) {\n        heap.push((y - x));\n    }\n}\nif (heap.size() === 0) {\n    return 0;\n}\nreturn heap.root();","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":7,"8":8,"9":9,"10":12,"11":13,"12":15},"statementBundles":{"4":{"startLine":3,"endLine":4},"9":{"startLine":9,"endLine":11},"11":{"startLine":13,"endLine":14}},"alternateStyles":{"close-to-source":{"code":"const heap = new MinHeap();\nfor (const stone of stones) {\n    heap.push(stone);\n}\nwhile (heap.size() > 1) {\n    if (heap.isEmpty()) throw new Error(\"IndexError\");\n    const poppedValue = heap.pop();\n    const x = poppedValue;\n    if (heap.isEmpty()) throw new Error(\"IndexError\");\n    const poppedValue2 = heap.pop();\n    const y = poppedValue2;\n    if (x !== y) {\n        heap.push((y - x));\n    }\n}\nif (heap.size() === 0) {\n    return 0;\n}\nreturn heap.root();","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":9,"8":12,"9":13,"10":16,"11":17,"12":19},"statementBundles":{"4":{"startLine":3,"endLine":4},"6":{"startLine":6,"endLine":8},"7":{"startLine":9,"endLine":11},"9":{"startLine":13,"endLine":15},"11":{"startLine":17,"endLine":18}}}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"const heap: MinHeap<number> = new MinHeap<number>();\nfor (const stone of stones) {\n    heap.push(stone);\n}\nwhile (heap.size() > 1) {\n    const x = heap.pop()!;\n    const y = heap.pop()!;\n    if (x !== y) {\n        heap.push((y - x));\n    }\n}\nif (heap.size() === 0) {\n    return 0;\n}\nreturn heap.root()!;","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":7,"8":8,"9":9,"10":12,"11":13,"12":15},"statementBundles":{"4":{"startLine":3,"endLine":4},"9":{"startLine":9,"endLine":11},"11":{"startLine":13,"endLine":14}},"alternateStyles":{"close-to-source":{"code":"const heap: MinHeap<number> = new MinHeap<number>();\nfor (const stone of stones) {\n    heap.push(stone);\n}\nwhile (heap.size() > 1) {\n    if (heap.isEmpty()) throw new Error(\"IndexError\");\n    const poppedValue = heap.pop()!;\n    const x = poppedValue;\n    if (heap.isEmpty()) throw new Error(\"IndexError\");\n    const poppedValue2 = heap.pop()!;\n    const y = poppedValue2;\n    if (x !== y) {\n        heap.push((y - x));\n    }\n}\nif (heap.size() === 0) {\n    return 0;\n}\nreturn heap.root()!;","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":9,"8":12,"9":13,"10":16,"11":17,"12":19},"statementBundles":{"4":{"startLine":3,"endLine":4},"6":{"startLine":6,"endLine":8},"7":{"startLine":9,"endLine":11},"9":{"startLine":13,"endLine":15},"11":{"startLine":17,"endLine":18}}}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"PriorityQueue<Integer> heap = new PriorityQueue<>();\nfor (Integer stone : stones) {\n    heap.offer(stone);\n}\nwhile (heap.size() > 1) {\n    int x = heap.poll();\n    int y = heap.poll();\n    if (x != y) {\n        heap.offer(y - x);\n    }\n}\nif (heap.isEmpty()) {\n    return 0;\n}\nreturn heap.peek();","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":7,"8":8,"9":9,"10":12,"11":13,"12":15},"statementBundles":{"4":{"startLine":3,"endLine":4},"9":{"startLine":9,"endLine":11},"11":{"startLine":13,"endLine":14}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"PriorityQueue<int, int> heap = new();\nforeach (int stone in stones) {\n    heap.Enqueue(stone, stone);\n}\nwhile (heap.Count > 1) {\n    int x = heap.Dequeue();\n    int y = heap.Dequeue();\n    if (x != y) {\n        heap.Enqueue(y - x, y - x);\n    }\n}\nif (heap.Count == 0) {\n    return 0;\n}\nreturn heap.Peek();","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":7,"8":8,"9":9,"10":12,"11":13,"12":15},"statementBundles":{"4":{"startLine":3,"endLine":4},"9":{"startLine":9,"endLine":11},"11":{"startLine":13,"endLine":14}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"vector<int> heap;\nfor (int stone : stones) {\n    heap.push_back(stone); push_heap(heap.begin(), heap.end(), greater<>());\n}\nwhile (heap.size() > 1) {\n    int x = heapPopValue(heap);\n    int y = heapPopValue(heap);\n    if (x != y) {\n        heap.push_back((y - x)); push_heap(heap.begin(), heap.end(), greater<>());\n    }\n}\nif (heap.empty()) {\n    return 0;\n}\nreturn heap[0];","lineMap":{"2":1,"3":2,"4":3,"5":5,"6":6,"7":7,"8":8,"9":9,"10":12,"11":13,"12":15},"statementBundles":{"4":{"startLine":3,"endLine":4},"9":{"startLine":9,"endLine":11},"11":{"startLine":13,"endLine":14}}}}}},{"id":"edge-case-intro","chapter":"Edge cases","kind":"info","eyebrow":"Try to break it","title":"Which inputs could break this?","summary":"The smash rule is only as safe as the inputs that test its boundaries.","ctaLabel":"Check edge cases","workspacePanel":"visualizer","body":["Two inputs press on the rule: a top pair that weighs exactly the same, and a pile that smashes itself down to nothing.","Does either one need handling the main loop does not already give it?"],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"edge-equal-top","title":"A top pair that ties","summary":"stones = [3,3,2]: the two heaviest both weigh 3.","state":{"heap":{"values":[3,3,2],"name":"heap","current":0,"highlighted":[1]}}},{"id":"edge-empties","title":"A pile that smashes itself away","summary":"stones = [2,2]: the last smash cancels both and leaves nothing.","state":{"heap":{"values":[2,2],"name":"heap","current":0,"highlighted":[1]}}}]}},{"id":"equal-top-probe","chapter":"Edge cases","kind":"case-probe","eyebrow":"Force a decision","title":"When the two heaviest are equal, what rejoins the heap?","summary":"stones = [3,3,2], so the top pair are both 3.","workspacePanel":"visualizer","options":[{"id":"nothing","label":"Nothing: both are destroyed and only the 2 is left","rationale":"Equal weights cancel, so no difference is produced and the heap shrinks to just the untouched stone 2.","isCorrect":true},{"id":"zero","label":"A stone of weight 0","rationale":"Pushing a 0 seeds a phantom stone; the rule only ever returns a positive difference, and equal stones leave none.","isCorrect":false},{"id":"one-three","label":"One of the 3s, since only the other is consumed","rationale":"Both equal stones are destroyed together; nothing weighing 3 survives the smash.","isCorrect":false}],"answer":"Nothing rejoins. The two 3s destroy each other, so the heap drops straight to the single stone 2, which becomes the answer.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"equal-top","state":{"heap":{"values":[2],"name":"heap","current":0}}}]}},{"id":"empty-probe","chapter":"Edge cases","kind":"case-probe","eyebrow":"Rule out a special case","title":"What should the answer be when the last smash empties the heap?","summary":"stones = [2,2], so the only two stones cancel and nothing is left.","workspacePanel":"visualizer","options":[{"id":"return-zero","label":"0, because every stone was destroyed","rationale":"The two equal stones cancel, leaving the heap empty, and an empty heap means no stone survived, so the answer is 0.","isCorrect":true},{"id":"read-top","label":"Whatever the heap top reads after the loop","rationale":"Reading the top of an empty heap has no value to return; the empty case has to be checked before reaching for a stone.","isCorrect":false},{"id":"last-diff","label":"The difference of the last pair, which is 0 anyway","rationale":"An equal smash never produces a stone, so there is no leftover to return; the answer comes from the heap being empty, not from a pushed-back 0.","isCorrect":false}],"answer":"Return 0. The equal pair empties the heap, and an empty heap means no stone is left, so the result is 0 rather than a read of a missing top.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"empty-pair","state":{"arrays":[{"name":"answer","values":[0],"current":0}]}}]}},{"id":"ready-to-code","chapter":"Code","kind":"info","eyebrow":"Get ready to code","title":"Turn the rule into code","summary":"Push the leftover back only when the two stones differ, then guard the final heap read for the empty case.","ctaLabel":"Start coding","workspacePanel":"visualizer","body":["Load every stone into one heap, then while two stones remain pull the heaviest pair, and when they differ drop the leftover weight back in. When the smashing stops, report the lone survivor or 0 for an empty heap."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"ready-heap","state":{"heap":{"values":[8,7,4,1,2,1],"name":"heap","current":0}}}]}},{"id":"coding","chapter":"Code","kind":"coding","source":"coding-checkpoints","eyebrow":"Code the rule","title":"Build the smash simulation","summary":"Build the simulation: load the stones, repeatedly smash the two largest, push any leftover weight, and return the final stone or 0.","workspacePanel":"code","checkpoints":[{"id":"init-heap","title":"Open one priority pool","description":"Before any smashing, create a single heap that will surrender its heaviest stone on demand.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"initializes_heap_storage","scope":"init-heap","readMode":"heap-value-query-v1"}]},"commonMistakes":["Keeping the stones in a plain list with no priority order","Rebuilding a new heap inside every round"],"hint":"One heap, created once, holds every stone still in play.","semanticSpec":{"intent":"Create the single priority heap that will hold all current stones before the simulation begins.","doneWhen":"This step is done when one empty heap container exists before the smash loop.","shouldFailWhen":"This step should fail if the storage is an unordered list, or a new heap is rebuilt each round.","roles":["heap container","created once","priority storage"],"mustProve":["A heap that can return its largest element exists before the loop.","The same heap is reused across every round."],"mustNotAccept":["Storing stones in a list with no priority behavior.","Allocating a fresh heap inside each smash round."],"proofSnippets":[{"id":"py-last-stone-init-heap","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []"}]}},{"id":"push-stones","title":"Load every stone in","description":"Place all the starting weights into the heap so the heaviest stone can be pulled out first.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"pushes_heap_values","scope":"heap-push","readMode":"heap-value-query-v1"}]},"commonMistakes":["Ordering the heap so the smallest weight surfaces first","Leaving the heap empty when the loop starts"],"hint":"Insert each weight so that the largest one sits at the top.","semanticSpec":{"intent":"Insert all input stone weights into the heap with the heaviest reachable at the top.","doneWhen":"This step is done when every starting weight is in the heap and the maximum is the next one out.","shouldFailWhen":"This step should fail if the smallest weight surfaces first, or some weights are never inserted.","roles":["bulk insertion","max reachable on top","all weights present"],"mustProve":["Every starting stone weight is added to the heap.","The ordering exposes the largest weight first."],"mustNotAccept":["Leaving the heap empty before the smash loop.","Arranging the heap so the smallest weight comes out first."],"proofSnippets":[{"id":"py-last-stone-push-stones","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)"}]}},{"id":"continue-while-pairs-remain","title":"Loop while two stones remain","description":"Keep smashing only while the heap still holds at least two stones to pick from.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"maintains_heap_size_bound","scope":"pair-loop","readMode":"heap-value-query-v1"}]},"commonMistakes":["Halting while two stones are still available","Entering the round body with only one stone left"],"hint":"Guard the round on the heap holding more than one stone.","semanticSpec":{"intent":"Run a round only when the heap contains two or more stones to smash together.","doneWhen":"This step is done when the loop continues for two-or-more stones and stops otherwise.","shouldFailWhen":"This step should fail if a round runs with fewer than two stones, or stops while two remain.","roles":["loop guard","two-or-more condition","round driver"],"mustProve":["Each round begins only when at least two stones are available.","The loop ends once fewer than two stones remain."],"mustNotAccept":["Running the round body with a single stone left.","Stopping the loop while two stones could still smash."],"proofSnippets":[{"id":"py-last-stone-continue-while-pairs-remain","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            pass"}]}},{"id":"pop-two-heaviest","title":"Pull out the two heaviest","description":"Each round removes the heaviest stone and then the next heaviest from the heap.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"extracts_heap_values","scope":"heap-pop","readMode":"heap-value-query-v1"}]},"commonMistakes":["Reading the top stone without removing it","Taking only one stone out per round"],"hint":"Remove from the top twice to get the two largest.","semanticSpec":{"intent":"Remove the two largest stones from the heap to be smashed together this round.","doneWhen":"This step is done when both the heaviest and second-heaviest are taken out of the heap.","shouldFailWhen":"This step should fail if a top stone is only peeked, or just one stone is removed.","roles":["two removals","largest then next-largest","taken off the heap"],"mustProve":["The heaviest stone is removed from the heap.","The next heaviest is also removed in the same round."],"mustNotAccept":["Inspecting the top stone without removing it.","Removing only one stone per round."],"proofSnippets":[{"id":"py-last-stone-pop-two-heaviest","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)"}]}},{"id":"push-remainder","title":"Return the leftover weight","description":"When the two stones differ, push their difference back so it can be smashed in a later round.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"reinserts_projected_heap_values","scope":"push-difference","readMode":"heap-value-query-v1"}]},"commonMistakes":["Pushing a difference of zero when the stones were equal","Dropping the leftover weight instead of returning it"],"hint":"A positive difference is a real stone and rejoins the heap.","semanticSpec":{"intent":"Insert the positive weight difference back into the heap when the two stones are unequal.","doneWhen":"This step is done when an unequal smash returns its difference and an equal smash returns nothing.","shouldFailWhen":"This step should fail if a zero difference is pushed, or a positive difference is lost.","roles":["conditional insertion","positive difference only","rejoins the heap"],"mustProve":["The positive difference of two unequal stones is pushed back.","Equal stones leave nothing behind to push."],"mustNotAccept":["Pushing a zero-weight stone after an equal smash.","Discarding the leftover difference of an unequal smash."],"proofSnippets":[{"id":"py-last-stone-push-remainder","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)\n            if x != y:\n                heapq.heappush(heap, -(y - x))"}]}},{"id":"return-last-stone","title":"Report the survivor","description":"After the loop, return the one remaining weight, or 0 when no stone is left.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"heap","fact":"returns_heap_top","scope":"return-empty-zero","readMode":"heap-value-query-v1"}]},"commonMistakes":["Returning the heap itself instead of a weight","Reading the top when the heap is empty"],"hint":"One stone left is the answer; an empty heap means 0.","semanticSpec":{"intent":"Return the final stone weight when one remains, and 0 when the heap is empty.","doneWhen":"This step is done when a surviving weight is returned and an empty heap yields 0.","shouldFailWhen":"This step should fail if the heap object is returned, or an empty heap is read for a value.","roles":["final result","survivor weight","empty yields zero"],"mustProve":["A surviving stone weight is returned when the heap is non-empty.","An empty heap returns 0."],"mustNotAccept":["Returning the heap container instead of a weight.","Reading a value from an empty heap."],"proofSnippets":[{"id":"py-last-stone-return-last-stone","language":"python","code":"class Solution:\n    def lastStoneWeight(self, stones: list[int]) -> int:\n        import heapq\n        heap = []\n        for stone in stones:\n            heapq.heappush(heap, -stone)\n        while len(heap) > 1:\n            y = -heapq.heappop(heap)\n            x = -heapq.heappop(heap)\n            if x != y:\n                heapq.heappush(heap, -(y - x))\n        if not heap:\n            return 0\n        return -heap[0]"}]}}]},{"id":"complete","chapter":"Code","kind":"complete","eyebrow":"Take it with you","title":"What to carry forward","summary":"Keep the stones in a heap, smash the top pair, push back a positive difference, and return the survivor.","body":["Last Stone Weight is a simulation that only ever needs one thing fast: the current heaviest stone. A heap gives that on demand, and the difference from each unequal smash sinks back in to compete again.","Push that leftover back every time, because it can climb to the top and become the heaviest stone a few rounds later.","Each pop or push walks one root-to-leaf path and there are about n of them, so the simulation is O(n log n), down from the O(n^2 log n) of re-sorting the pile every round."],"takeaways":[{"title":"Reach for a heap when you keep needing the max","body":"When a loop repeatedly pulls the largest element from a changing set, a heap surfaces it in log time instead of re-sorting."},{"title":"A positive difference is a real stone","body":"Push y - x back whenever the two stones differ, because that leftover can become the heaviest in a later round."},{"title":"An empty heap answers 0","body":"When the final smash destroys both stones, no survivor is left, so guard the read and return 0."}],"nextAction":"Submit when you are ready. TraceCode will run the final checks against the code you wrote.","workspacePanel":"code"}],"slidesOrigin":"authored"}}
