|
Download cp/cp-10052.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cp/cp-10052.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm/cp/cp-10052.jsonl
-
curl -L -o cp-10052.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cp/cp-10052.jsonl
2.16 kB
| {"type": "session", "harness": "opencode", "id": "cp-10052", "name": "LeetCode 0546: Remove Boxes"} | |
| {"type": "message", "message": {"role": "system", "content": "You are an expert LeetCode problem solver. You solve problems efficiently with clean code."}} | |
| {"type": "message", "message": {"role": "user", "content": "Problem: Remove Boxes (Difficulty: Hard)\nTags: Array, Dynamic Programming, Memoization\n\nYou are given several boxes with different colors represented by different positive numbers.\nYou may experience several rounds to remove boxes until there is no box left. Each time you can choose some continuous boxes with the same color (i.e., composed of k boxes, k >= 1), remove them and get k * k points.\nReturn the maximum points you can get.\n\nExample 1:\nInput: boxes = [1,3,2,2,2,3,4,3,1]\nOutput: 23\nExplanation:\n[1, 3, 2, 2, 2, 3, 4, 3, 1] \n----> [1, 3, 3, 4, 3, 1] (3*3=9 points) \n----> [1, 3, 3, 3, 1] (1*1=1 points) \n----> [1, 1] (3*3=9 points) \n----> [] (2*2=4 points)\n\nExample 2:\nInput: boxes = [1,1,1]\nOutput: 9\n\nExample 3:\nInput: boxes = [1]\nOutput: 1\n\nConstraints:\n- 1 <= boxes.length <= 100\n- 1 <= boxes[i] <= 100"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "# Time: O(n^3) ~ O(n^4)\n# Space: O(n^3)\n\nclass Solution(object):\n def removeBoxes(self, boxes):\n \"\"\"\n :type boxes: List[int]\n :rtype: int\n \"\"\"\n def dfs(boxes, l, r, k, lookup):\n if l > r: return 0\n if lookup[l][r][k]: return lookup[l][r][k]\n\n ll, kk = l, k\n while l < r and boxes[l+1] == boxes[l]:\n l += 1\n k += 1\n result = dfs(boxes, l+1, r, 0, lookup) + (k+1) ** 2\n for i in range(l+1, r+1):\n if boxes[i] == boxes[l]:\n result = max(result, dfs(boxes, l+1, i-1, 0, lookup) + dfs(boxes, i, r, k+1, lookup))\n lookup[ll][r][kk] = result\n return result\n\n lookup = [[[0]*len(boxes) for _ in range(len(boxes)) ] for _ in range(len(boxes)) ]\n return dfs(boxes, 0, len(boxes)-1, 0, lookup)\n\n"}} | |