|
Download cp/cp-10002.jsonl from winapiadmin/tinycodinglm: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cp/cp-10002.jsonl
- Command line
-
hf download hf://datasets/winapiadmin/tinycodinglm/cp/cp-10002.jsonl
-
curl -L -o cp-10002.jsonl https://huggingface.co/datasets/winapiadmin/tinycodinglm/resolve/main/cp/cp-10002.jsonl
2.26 kB
| {"type": "session", "harness": "opencode", "id": "cp-10002", "name": "LeetCode 0493: Reverse Pairs"} | |
| {"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: Reverse Pairs (Difficulty: Hard)\nTags: Array, Binary Search, Divide and Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set\n\nGiven an integer array nums, return the number of reverse pairs in the array.\nA reverse pair is a pair (i, j) where:\n\nExample 1:\nInput: nums = [1,3,2,3,1]\nOutput: 2\nExplanation: The reverse pairs are:\n(1, 4) --> nums[1] = 3, nums[4] = 1, 3 > 2 * 1\n(3, 4) --> nums[3] = 3, nums[4] = 1, 3 > 2 * 1\n\nExample 2:\nInput: nums = [2,4,3,5,1]\nOutput: 3\nExplanation: The reverse pairs are:\n(1, 4) --> nums[1] = 4, nums[4] = 1, 4 > 2 * 1\n(2, 4) --> nums[2] = 3, nums[4] = 1, 3 > 2 * 1\n(3, 4) --> nums[3] = 5, nums[4] = 1, 5 > 2 * 1\n\nConstraints:\n- 1 <= nums.length <= 5 * 10^4\n- -2^31 <= nums[i] <= 2^31 - 1"}} | |
| {"type": "message", "message": {"role": "assistant", "content": "# Time: O(nlogn)\n# Space: O(n)\n\nclass Solution(object):\n def reversePairs(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n def merge(nums, start, mid, end):\n r = mid + 1\n tmp = []\n for i in range(start, mid + 1):\n while r <= end and nums[i] > nums[r]:\n tmp.append(nums[r])\n r += 1\n tmp.append(nums[i])\n nums[start:start+len(tmp)] = tmp\n\n def countAndMergeSort(nums, start, end):\n if end - start <= 0:\n return 0\n\n mid = start + (end - start) / 2\n count = countAndMergeSort(nums, start, mid) + countAndMergeSort(nums, mid + 1, end)\n r = mid + 1\n for i in range(start, mid + 1):\n while r <= end and nums[i] > nums[r] * 2:\n r += 1\n count += r - (mid + 1)\n merge(nums, start, mid, end)\n return count\n\n return countAndMergeSort(nums, 0, len(nums) - 1)\n\n"}} | |