Upload folder using huggingface_hub (part 15)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- cp/cp-9877.jsonlAdded+4
- cp/cp-9880.jsonlAdded+4
- cp/cp-9881.jsonlAdded+4
- cp/cp-9882.jsonlAdded+4
- cp/cp-9883.jsonlAdded+4
- cp/cp-9884.jsonlAdded+4
- cp/cp-9885.jsonlAdded+4
- cp/cp-9886.jsonlAdded+4
- cp/cp-9887.jsonlAdded+4
- cp/cp-9889.jsonlAdded+4
- cp/cp-9890.jsonlAdded+4
- cp/cp-9891.jsonlAdded+4
- cp/cp-9892.jsonlAdded+4
- cp/cp-9893.jsonlAdded+4
- cp/cp-9894.jsonlAdded+4
- cp/cp-9895.jsonlAdded+4
- cp/cp-9896.jsonlAdded+4
- cp/cp-9897.jsonlAdded+4
- cp/cp-9898.jsonlAdded+4
- cp/cp-9899.jsonlAdded+4
- cp/cp-9900.jsonlAdded+4
- cp/cp-9901.jsonlAdded+4
- cp/cp-9902.jsonlAdded+4
- cp/cp-9903.jsonlAdded+4
- cp/cp-9904.jsonlAdded+4
- cp/cp-9905.jsonlAdded+4
- cp/cp-9906.jsonlAdded+4
- cp/cp-9907.jsonlAdded+4
- cp/cp-9908.jsonlAdded+4
- cp/cp-9909.jsonlAdded+4
- cp/cp-9910.jsonlAdded+4
- cp/cp-9911.jsonlAdded+4
- cp/cp-9912.jsonlAdded+4
- cp/cp-9913.jsonlAdded+4
- cp/cp-9914.jsonlAdded+4
- cp/cp-9915.jsonlAdded+4
- cp/cp-9916.jsonlAdded+4
- cp/cp-9918.jsonlAdded+4
- cp/cp-9919.jsonlAdded+4
- cp/cp-9921.jsonlAdded+4
- cp/cp-9922.jsonlAdded+4
- cp/cp-9923.jsonlAdded+4
- cp/cp-9924.jsonlAdded+4
- cp/cp-9925.jsonlAdded+4
- cp/cp-9926.jsonlAdded+4
- cp/cp-9928.jsonlAdded+4
- cp/cp-9929.jsonlAdded+4
- cp/cp-9930.jsonlAdded+4
- cp/cp-9932.jsonlAdded+4
- cp/cp-9933.jsonlAdded+4
1234{"type": "session", "harness": "opencode", "id": "cp-9877", "name": "LeetCode 0368: Largest Divisible Subset"}{"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: Largest Divisible Subset (Difficulty: Medium)\nTags: Array, Math, Dynamic Programming, Sorting\n\nGiven a set of distinct positive integers nums, return the largest subset answer such that every pair (answer[i], answer[j]) of elements in this subset satisfies:\nIf there are multiple solutions, return any of them.\n\nExample 1:\nInput: nums = [1,2,3]\nOutput: [1,2]\nExplanation: [1,3] is also accepted.\n\nExample 2:\nInput: nums = [1,2,4,8]\nOutput: [1,2,4,8]\n\nConstraints:\n- 1 <= nums.length <= 1000\n- 1 <= nums[i] <= 2 * 10^9\n- All the integers in nums are unique."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n^2)\n# Space: O(n)\n\nclass Solution(object):\n def largestDivisibleSubset(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: List[int]\n \"\"\"\n if not nums:\n return []\n\n nums.sort()\n dp = [1] * len(nums)\n prev = [-1] * len(nums)\n largest_idx = 0\n for i in range(len(nums)):\n for j in range(i):\n if nums[i] % nums[j] == 0:\n if dp[i] < dp[j] + 1:\n dp[i] = dp[j] + 1\n prev[i] = j\n if dp[largest_idx] < dp[i]:\n largest_idx = i\n\n result = []\n i = largest_idx\n while i != -1:\n result.append(nums[i])\n i = prev[i]\n return result[::-1]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9880", "name": "LeetCode 0371: Sum Of Two Integers"}{"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: Sum of Two Integers (Difficulty: Medium)\nTags: Math, Bit Manipulation\n\nGiven two integers a and b, return the sum of the two integers without using the operators + and -.\n\nExample 1:\nInput: a = 1, b = 2\nOutput: 3\n\nExample 2:\nInput: a = 2, b = 3\nOutput: 5\n\nConstraints:\n- -1000 <= a, b <= 1000"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(1)\n# Space: O(1)\n\nclass Solution(object):\n def getSum(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"\n bit_length = 32\n neg_bit, mask = (1 << bit_length) >> 1, ~(~0 << bit_length)\n\n a = (a | ~mask) if (a & neg_bit) else (a & mask)\n b = (b | ~mask) if (b & neg_bit) else (b & mask)\n\n while b:\n carry = a & b\n a ^= b\n a = (a | ~mask) if (a & neg_bit) else (a & mask)\n b = carry << 1\n b = (b | ~mask) if (b & neg_bit) else (b & mask)\n\n return a\n\n def getSum2(self, a, b):\n \"\"\"\n :type a: int\n :type b: int\n :rtype: int\n \"\"\"\n # 32 bits integer max\n MAX = 0x7FFFFFFF\n # 32 bits interger min\n MIN = 0x80000000\n # mask to get last 32 bits\n mask = 0xFFFFFFFF\n while b:\n # ^ get different bits and & gets double 1s, << moves carry\n a, b = (a ^ b) & mask, ((a & b) << 1) & mask\n # if a is negative, get a's 32 bits complement positive first\n # then get 32-bit positive's Python complement negative\n return a if a <= MAX else ~(a ^ mask)\n\n def minus(self, a, b):\n b = self.getSum(~b, 1)\n return self.getSum(a, b)\n\n def multiply(self, a, b):\n isNeg = (a > 0) ^ (b > 0)\n x = a if a > 0 else self.getSum(~a, 1)\n y = b if b > 0 else self.getSum(~b, 1)\n ans = 0\n while y & 0x01:\n ans = self.getSum(ans, x)\n y >>= 1\n x <<= 1\n return self.getSum(~ans, 1) if isNeg else ans\n\n def divide(self, a, b):\n isNeg = (a > 0) ^ (b > 0)\n x = a if a > 0 else self.getSum(~a, 1)\n y = b if b > 0 else self.getSum(~b, 1)\n ans = 0\n for i in range(31, -1, -1):\n if (x >> i) >= y:\n x = self.minus(x, y << i)\n ans = self.getSum(ans, 1 << i)\n return self.getSum(~ans, 1) if isNeg else ans\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9881", "name": "LeetCode 0372: Super Pow"}{"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: Super Pow (Difficulty: Medium)\nTags: Math, Divide and Conquer\n\nYour task is to calculate ab mod 1337 where a is a positive integer and b is an extremely large positive integer given in the form of an array.\n\nExample 1:\nInput: a = 2, b = [3]\nOutput: 8\n\nExample 2:\nInput: a = 2, b = [1,0]\nOutput: 1024\n\nExample 3:\nInput: a = 1, b = [4,3,3,8,5,2]\nOutput: 1\n\nConstraints:\n- 1 <= a <= 2^31 - 1\n- 1 <= b.length <= 2000\n- 0 <= b[i] <= 9\n- b does not contain leading zeros."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n), n is the size of b.\n# Space: O(1)\n\nclass Solution(object):\n def superPow(self, a, b):\n \"\"\"\n :type a: int\n :type b: List[int]\n :rtype: int\n \"\"\"\n def myPow(a, n, b):\n result = 1\n x = a % b\n while n:\n if n & 1:\n result = result * x % b\n n >>= 1\n x = x * x % b\n return result % b\n\n result = 1\n for digit in b:\n result = myPow(result, 10, 1337) * myPow(a, digit, 1337) % 1337\n return result\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9882", "name": "LeetCode 0373: Find K Pairs With Smallest Sums"}{"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: Find K Pairs with Smallest Sums (Difficulty: Medium)\nTags: Array, Heap (Priority Queue)\n\nYou are given two integer arrays nums1 and nums2 sorted in non-decreasing order and an integer k.\nDefine a pair (u, v) which consists of one element from the first array and one element from the second array.\nReturn the k pairs (u1, v1), (u2, v2), ..., (uk, vk) with the smallest sums.\n\nExample 1:\nInput: nums1 = [1,7,11], nums2 = [2,4,6], k = 3\nOutput: [[1,2],[1,4],[1,6]]\nExplanation: The first 3 pairs are returned from the sequence: [1,2],[1,4],[1,6],[7,2],[7,4],[11,2],[7,6],[11,4],[11,6]\n\nExample 2:\nInput: nums1 = [1,1,2], nums2 = [1,2,3], k = 2\nOutput: [[1,1],[1,1]]\nExplanation: The first 2 pairs are returned from the sequence: [1,1],[1,1],[1,2],[2,1],[1,2],[2,2],[1,3],[1,3],[2,3]\n\nConstraints:\n- 1 <= nums1.length, nums2.length <= 10^5\n- -10^9 <= nums1[i], nums2[i] <= 10^9\n- nums1 and nums2 both are sorted in non-decreasing order.\n- 1 <= k <= 10^4\n- k <= nums1.length * nums2.length"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(k * log(min(n, m, k))), where n is the size of num1, and m is the size of num2.\n# Space: O(min(n, m, k))\n\nfrom heapq import heappush, heappop\n\nclass Solution(object):\n def kSmallestPairs(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n pairs = []\n if len(nums1) > len(nums2):\n tmp = self.kSmallestPairs(nums2, nums1, k)\n for pair in tmp:\n pairs.append([pair[1], pair[0]])\n return pairs\n\n min_heap = []\n def push(i, j):\n if i < len(nums1) and j < len(nums2):\n heappush(min_heap, [nums1[i] + nums2[j], i, j])\n\n push(0, 0)\n while min_heap and len(pairs) < k:\n _, i, j = heappop(min_heap)\n pairs.append([nums1[i], nums2[j]])\n push(i, j + 1)\n if j == 0:\n push(i + 1, 0) # at most queue min(n, m) space\n return pairs\n\n\n# time: O(mn * log k)\n# space: O(k)\nfrom heapq import nsmallest\nfrom itertools import product\n\n\nclass Solution2(object):\n def kSmallestPairs(self, nums1, nums2, k):\n \"\"\"\n :type nums1: List[int]\n :type nums2: List[int]\n :type k: int\n :rtype: List[List[int]]\n \"\"\"\n return nsmallest(k, product(nums1, nums2), key=sum)\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9883", "name": "LeetCode 0374: Guess Number Higher Or Lower"}{"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: Guess Number Higher or Lower (Difficulty: Easy)\nTags: Binary Search, Interactive\n\nWe are playing the Guess Game. The game is as follows:\nI pick a number from 1 to n. You have to guess which number I picked.\nEvery time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.\nYou call a pre-defined API int guess(int num), which returns three possible results:\nReturn the number that I picked.\n\nExample 1:\nInput: n = 10, pick = 6\nOutput: 6\n\nExample 2:\nInput: n = 1, pick = 1\nOutput: 1\n\nExample 3:\nInput: n = 2, pick = 1\nOutput: 1\n\nConstraints:\n- 1 <= n <= 2^31 - 1\n- 1 <= pick <= n"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(logn)\n# Space: O(1)\n\nclass Solution(object):\n def guessNumber(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n left, right = 1, n\n while left <= right:\n mid = left + (right - left) / 2\n if guess(mid) <= 0: # noqa\n right = mid - 1\n else:\n left = mid + 1\n return left\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9884", "name": "LeetCode 0375: Guess Number Higher Or Lower Ii"}{"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: Guess Number Higher or Lower II (Difficulty: Medium)\nTags: Math, Dynamic Programming, Game Theory\n\nWe are playing the Guessing Game. The game will work as follows:\nGiven a particular n, return the minimum amount of money you need to guarantee a win regardless of what number I pick.\n\nExample 1:\nInput: n = 10\nOutput: 16\nExplanation: The winning strategy is as follows:\n- The range is [1,10]. Guess 7.\n - If this is my number, your total is $0. Otherwise, you pay $7.\n - If my number is higher, the range is [8,10]. Guess 9.\n - If this is my number, your total is $7. Otherwise, you pay $9.\n - If my number is higher, it must be 10. Guess 10. Your total is $7 + $9 = $16.\n - If my number is lower, it must be 8. Guess 8. Your total is $7 + $9 = $16.\n - If my number is lower, the range is [1,6]. Guess 3.\n - If this is my number, your total is $7. Otherwise, you pay $3.\n - If my number is higher, the range is [4,6]. Guess 5.\n - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $5.\n - If my number is higher, it must be 6. Guess 6. Your total is $7 + $3 + $5 = $15.\n - If my number is lower, it must be 4. Guess 4. Your total is $7 + $3 + $5 = $15.\n - If my number is lower, the range is [1,2]. Guess 1.\n - If this is my number, your total is $7 + $3 = $10. Otherwise, you pay $1.\n - If my number is higher, it must be 2. Guess 2. Your total is $7 + $3 + $1 = $11.\nThe worst case in all these scenarios is that you pay $16. Hence, you only need $16 to guarantee a win.\n\nExample 2:\nInput: n = 1\nOutput: 0\nExplanation: There is only one possible number, so you can guess 1 and not have to pay anything.\n\nExample 3:\nInput: n = 2\nOutput: 1\nExplanation: There are two possible numbers, 1 and 2.\n- Guess 1.\n - If this is my number, your total is $0. Otherwise, you pay $1.\n - If my number is higher, it must be 2. Guess 2. Your total is $1.\nThe worst case is that you pay $1.\n\nConstraints:\n- 1 <= n <= 200"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n^3)\n# Space: O(n^2)\nclass Solution(object):\n def getMoneyAmount(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n dp = [[0]*(n+1) for _ in range(n+1)] # dp[i][j]: min pay in [i+1, j+1)\n for j in range(n+1):\n for i in reversed(range(j-1)):\n dp[i][j] = min((k+1) + max(dp[i][k], dp[k+1][j]) for k in range(i, j))\n return dp[0][n]\n\n\n# Time: O(n^3)\n# Space: O(n^2)\nclass Solution2(object):\n def getMoneyAmount(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n dp = [[0]*(n+1) for _ in range(n+1)] # dp[i][j]: min pay in [i+1, j+1)\n for i in reversed(range(n)):\n for j in range(i+2, n+1):\n dp[i][j] = min((k+1) + max(dp[i][k], dp[k+1][j]) for k in range(i, j))\n return dp[0][n]\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9885", "name": "LeetCode 0376: Wiggle Subsequence"}{"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: Wiggle Subsequence (Difficulty: Medium)\nTags: Array, Dynamic Programming, Greedy\n\nA wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence with one element and a sequence with two non-equal elements are trivially wiggle sequences.\nA subsequence is obtained by deleting some elements (possibly zero) from the original sequence, leaving the remaining elements in their original order.\nGiven an integer array nums, return the length of the longest wiggle subsequence of nums.\nFollow up: Could you solve this in O(n) time?\n\nExample 1:\nInput: nums = [1,7,4,9,2,5]\nOutput: 6\nExplanation: The entire sequence is a wiggle sequence with differences (6, -3, 5, -7, 3).\n\nExample 2:\nInput: nums = [1,17,5,10,13,15,10,5,16,8]\nOutput: 7\nExplanation: There are several subsequences that achieve this length.\nOne is [1, 17, 10, 13, 10, 16, 8] with differences (16, -7, 3, -3, 6, -8).\n\nExample 3:\nInput: nums = [1,2,3,4,5,6,7,8,9]\nOutput: 2\n\nConstraints:\n- 1 <= nums.length <= 1000\n- 0 <= nums[i] <= 1000"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def wiggleMaxLength(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n if len(nums) < 2:\n return len(nums)\n\n length, up = 1, None\n\n for i in range(1, len(nums)):\n if nums[i - 1] < nums[i] and (up is None or up is False):\n length += 1\n up = True\n elif nums[i - 1] > nums[i] and (up is None or up is True):\n length += 1\n up = False\n\n return length\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9886", "name": "LeetCode 0377: Combination Sum Iv"}{"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: Combination Sum IV (Difficulty: Medium)\nTags: Array, Dynamic Programming\n\nGiven an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target.\nThe test cases are generated so that the answer can fit in a 32-bit integer.\nFollow up: What if negative numbers are allowed in the given array? How does it change the problem? What limitation we need to add to the question to allow negative numbers?\n\nExample 1:\nInput: nums = [1,2,3], target = 4\nOutput: 7\nExplanation:\nThe possible combination ways are:\n(1, 1, 1, 1)\n(1, 1, 2)\n(1, 2, 1)\n(1, 3)\n(2, 1, 1)\n(2, 2)\n(3, 1)\nNote that different sequences are counted as different combinations.\n\nExample 2:\nInput: nums = [9], target = 3\nOutput: 0\n\nConstraints:\n- 1 <= nums.length <= 200\n- 1 <= nums[i] <= 1000\n- All the elements of nums are unique.\n- 1 <= target <= 1000"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(nlon + n * t), t is the value of target.\n# Space: O(t)\n\nclass Solution(object):\n def combinationSum4(self, nums, target):\n \"\"\"\n :type nums: List[int]\n :type target: int\n :rtype: int\n \"\"\"\n dp = [0] * (target+1)\n dp[0] = 1\n nums.sort()\n\n for i in range(1, target+1):\n for j in range(len(nums)):\n if nums[j] <= i:\n dp[i] += dp[i - nums[j]]\n else:\n break\n\n return dp[target]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9887", "name": "LeetCode 0378: Kth Smallest Element In A Sorted Matrix"}{"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: Kth Smallest Element in a Sorted Matrix (Difficulty: Medium)\nTags: Array, Binary Search, Sorting, Heap (Priority Queue), Matrix\n\nGiven an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix.\nNote that it is the kth smallest element in the sorted order, not the kth distinct element.\nYou must find a solution with a memory complexity better than O(n2).\nFollow up:\n\nExample 1:\nInput: matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8\nOutput: 13\nExplanation: The elements in the matrix are [1,5,9,10,11,12,13,13,15], and the 8th smallest number is 13\n\nExample 2:\nInput: matrix = [[-5]], k = 1\nOutput: -5\n\nConstraints:\n- n == matrix.length == matrix[i].length\n- 1 <= n <= 300\n- -10^9 <= matrix[i][j] <= 10^9\n- All the rows and columns of matrix are guaranteed to be sorted in non-decreasing order.\n- 1 <= k <= n2"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(k * log(min(n, m, k))), with n x m matrix\n# Space: O(min(n, m, k))\n\nfrom heapq import heappush, heappop\n\nclass Solution(object):\n def kthSmallest(self, matrix, k):\n \"\"\"\n :type matrix: List[List[int]]\n :type k: int\n :rtype: int\n \"\"\"\n kth_smallest = 0\n min_heap = []\n\n def push(i, j):\n if len(matrix) > len(matrix[0]):\n if i < len(matrix[0]) and j < len(matrix):\n heappush(min_heap, [matrix[j][i], i, j])\n else:\n if i < len(matrix) and j < len(matrix[0]):\n heappush(min_heap, [matrix[i][j], i, j])\n\n push(0, 0)\n while min_heap and k > 0:\n kth_smallest, i, j = heappop(min_heap)\n push(i, j + 1)\n if j == 0:\n push(i + 1, 0)\n k -= 1\n\n return kth_smallest\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9889", "name": "LeetCode 0380: Insert Delete Getrandom O1"}{"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: Insert Delete GetRandom O(1) (Difficulty: Medium)\nTags: Array, Hash Table, Math, Design, Randomized\n\nImplement the RandomizedSet class:\nYou must implement the functions of the class such that each function works in average O(1) time complexity.\n\nExample 1:\nInput\n[\"RandomizedSet\", \"insert\", \"remove\", \"insert\", \"getRandom\", \"remove\", \"insert\", \"getRandom\"]\n[[], [1], [2], [2], [], [1], [2], []]\nOutput\n[null, true, false, true, 2, true, false, 2]\n\nExplanation\nRandomizedSet randomizedSet = new RandomizedSet();\nrandomizedSet.insert(1); // Inserts 1 to the set. Returns true as 1 was inserted successfully.\nrandomizedSet.remove(2); // Returns false as 2 does not exist in the set.\nrandomizedSet.insert(2); // Inserts 2 to the set, returns true. Set now contains [1,2].\nrandomizedSet.getRandom(); // getRandom() should return either 1 or 2 randomly.\nrandomizedSet.remove(1); // Removes 1 from the set, returns true. Set now contains [2].\nrandomizedSet.insert(2); // 2 was already in the set, so return false.\nrandomizedSet.getRandom(); // Since 2 is the only number in the set, getRandom() will always return 2.\n\nConstraints:\n- -2^31 <= val <= 2^31 - 1\n- At most 2 * 10^5 calls will be made to insert, remove, and getRandom.\n- There will be at least one element in the data structure when getRandom is called."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(1)\n# Space: O(n)\n\nfrom random import randint\n\nclass RandomizedSet(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n self.__set = []\n self.__used = {}\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the set. Returns true if the set did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n if val in self.__used:\n return False\n\n self.__set += val,\n self.__used[val] = len(self.__set)-1\n\n return True\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the set. Returns true if the set contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n if val not in self.__used:\n return False\n\n self.__used[self.__set[-1]] = self.__used[val]\n self.__set[self.__used[val]], self.__set[-1] = self.__set[-1], self.__set[self.__used[val]]\n\n self.__used.pop(val)\n self.__set.pop()\n\n return True\n\n def getRandom(self):\n \"\"\"\n Get a random element from the set.\n :rtype: int\n \"\"\"\n return self.__set[randint(0, len(self.__set)-1)]\n\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9890", "name": "LeetCode 0381: Insert Delete Getrandom O1 Duplicates Allowed"}{"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: Insert Delete GetRandom O(1) - Duplicates allowed (Difficulty: Hard)\nTags: Array, Hash Table, Math, Design, Randomized\n\nRandomizedCollection is a data structure that contains a collection of numbers, possibly duplicates (i.e., a multiset). It should support inserting and removing specific elements and also reporting a random element.\nImplement the RandomizedCollection class:\nYou must implement the functions of the class such that each function works on average O(1) time complexity.\nNote: The test cases are generated such that getRandom will only be called if there is at least one item in the RandomizedCollection.\n\nExample 1:\nInput\n[\"RandomizedCollection\", \"insert\", \"insert\", \"insert\", \"getRandom\", \"remove\", \"getRandom\"]\n[[], [1], [1], [2], [], [1], []]\nOutput\n[null, true, false, true, 2, true, 1]\n\nExplanation\nRandomizedCollection randomizedCollection = new RandomizedCollection();\nrandomizedCollection.insert(1); // return true since the collection does not contain 1.\n // Inserts 1 into the collection.\nrandomizedCollection.insert(1); // return false since the collection contains 1.\n // Inserts another 1 into the collection. Collection now contains [1,1].\nrandomizedCollection.insert(2); // return true since the collection does not contain 2.\n // Inserts 2 into the collection. Collection now contains [1,1,2].\nrandomizedCollection.getRandom(); // getRandom should:\n // - return 1 with probability 2/3, or\n // - return 2 with probability 1/3.\nrandomizedCollection.remove(1); // return true since the collection contains 1.\n // Removes 1 from the collection. Collection now contains [1,2].\nrandomizedCollection.getRandom(); // getRandom should return 1 or 2, both equally likely.\n\nConstraints:\n- -2^31 <= val <= 2^31 - 1\n- At most 2 * 10^5 calls in total will be made to insert, remove, and getRandom.\n- There will be at least one element in the data structure when getRandom is called."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(1)\n# Space: O(n)\n\nfrom random import randint\nfrom collections import defaultdict\n\nclass RandomizedCollection(object):\n\n def __init__(self):\n \"\"\"\n Initialize your data structure here.\n \"\"\"\n self.__list = []\n self.__used = defaultdict(list)\n\n\n def insert(self, val):\n \"\"\"\n Inserts a value to the collection. Returns true if the collection did not already contain the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n has = val in self.__used\n\n self.__list += (val, len(self.__used[val])),\n self.__used[val] += len(self.__list)-1,\n\n return not has\n\n\n def remove(self, val):\n \"\"\"\n Removes a value from the collection. Returns true if the collection contained the specified element.\n :type val: int\n :rtype: bool\n \"\"\"\n if val not in self.__used:\n return False\n\n self.__used[self.__list[-1][0]][self.__list[-1][1]] = self.__used[val][-1]\n self.__list[self.__used[val][-1]], self.__list[-1] = self.__list[-1], self.__list[self.__used[val][-1]]\n\n self.__used[val].pop()\n if not self.__used[val]:\n self.__used.pop(val)\n self.__list.pop()\n\n return True\n\n def getRandom(self):\n \"\"\"\n Get a random element from the collection.\n :rtype: int\n \"\"\"\n return self.__list[randint(0, len(self.__list)-1)][0]\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9891", "name": "LeetCode 0382: Linked List Random Node"}{"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: Linked List Random Node (Difficulty: Medium)\nTags: Linked List, Math, Reservoir Sampling, Randomized\n\nGiven a singly linked list, return a random node's value from the linked list. Each node must have the same probability of being chosen.\nImplement the Solution class:\nFollow up:\n\nExample 1:\nInput\n[\"Solution\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\", \"getRandom\"]\n[[[1, 2, 3]], [], [], [], [], []]\nOutput\n[null, 1, 3, 2, 2, 3]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.getRandom(); // return 1\nsolution.getRandom(); // return 3\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 2\nsolution.getRandom(); // return 3\n// getRandom() should return either 1, 2, or 3 randomly. Each element should have equal probability of returning.\n\nConstraints:\n- The number of nodes in the linked list will be in the range [1, 104].\n- -10^4 <= Node.val <= 10^4\n- At most 104 calls will be made to getRandom."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: ctor: O(1)\n# getRandom: O(n)\n# Space: O(1)\n\nfrom random import randint\n\n\n# if the length is unknown without using extra space\nclass Solution(object):\n\n def __init__(self, head):\n \"\"\"\n :type head: Optional[ListNode]\n \"\"\"\n self.__head = head\n\n\n # Proof of Reservoir Sampling:\n # https://discuss.leetcode.com/topic/53753/brief-explanation-for-reservoir-sampling\n def getRandom(self):\n \"\"\"\n :rtype: int\n \"\"\"\n reservoir = -1\n curr, n = self.__head, 0\n while curr:\n reservoir = curr.val if randint(1, n+1) == 1 else reservoir\n curr, n = curr.next, n+1\n return reservoir\n\n\n# Time: ctor: O(n)\n# getRandom: O(1)\n# Space: O(n)\nfrom random import randint\n\n\n# if the length is known with using extra space\nclass Solution2(object):\n\n def __init__(self, head):\n \"\"\"\n :type head: Optional[ListNode]\n \"\"\"\n self.__lookup = []\n while head:\n self.__lookup.append(head.val)\n head = head.next\n \n\n def getRandom(self):\n \"\"\"\n :rtype: int\n \"\"\"\n return self.__lookup[randint(0, len(self.__lookup)-1)]\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9892", "name": "LeetCode 0383: Ransom Note"}{"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: Ransom Note (Difficulty: Easy)\nTags: Hash Table, String, Counting\n\nGiven two strings ransomNote and magazine, return true if ransomNote can be constructed by using the letters from magazine and false otherwise.\nEach letter in magazine can only be used once in ransomNote.\n\nExample 1:\nInput: ransomNote = \"a\", magazine = \"b\"\nOutput: false\n\nExample 2:\nInput: ransomNote = \"aa\", magazine = \"ab\"\nOutput: false\n\nExample 3:\nInput: ransomNote = \"aa\", magazine = \"aab\"\nOutput: true\n\nConstraints:\n- 1 <= ransomNote.length, magazine.length <= 10^5\n- ransomNote and magazine consist of lowercase English letters."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def canConstruct(self, ransomNote, magazine):\n \"\"\"\n :type ransomNote: str\n :type magazine: str\n :rtype: bool\n \"\"\"\n counts = [0] * 26\n letters = 0\n\n for c in ransomNote:\n if counts[ord(c) - ord('a')] == 0:\n letters += 1\n counts[ord(c) - ord('a')] += 1\n\n for c in magazine:\n counts[ord(c) - ord('a')] -= 1\n if counts[ord(c) - ord('a')] == 0:\n letters -= 1\n if letters == 0:\n break\n\n return letters == 0\n\n# Time: O(n)\n# Space: O(1)\nimport collections\n\nclass Solution2(object):\n def canConstruct(self, ransomNote, magazine):\n \"\"\"\n :type ransomNote: str\n :type magazine: str\n :rtype: bool\n \"\"\"\n return not collections.Counter(ransomNote) - collections.Counter(magazine)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9893", "name": "LeetCode 0384: Shuffle An Array"}{"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: Shuffle an Array (Difficulty: Medium)\nTags: Array, Math, Design, Randomized\n\nGiven an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.\nImplement the Solution class:\n\nExample 1:\nInput\n[\"Solution\", \"shuffle\", \"reset\", \"shuffle\"]\n[[[1, 2, 3]], [], [], []]\nOutput\n[null, [3, 1, 2], [1, 2, 3], [1, 3, 2]]\n\nExplanation\nSolution solution = new Solution([1, 2, 3]);\nsolution.shuffle(); // Shuffle the array [1,2,3] and return its result.\n // Any permutation of [1,2,3] must be equally likely to be returned.\n // Example: return [3, 1, 2]\nsolution.reset(); // Resets the array back to its original configuration [1,2,3]. Return [1, 2, 3]\nsolution.shuffle(); // Returns the random shuffling of array [1,2,3]. Example: return [1, 3, 2]\n\nConstraints:\n- 1 <= nums.length <= 50\n- -10^6 <= nums[i] <= 10^6\n- All the elements of nums are unique.\n- At most 104 calls in total will be made to reset and shuffle."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(n)\n\nimport random\n\n\nclass Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n\n :type nums: List[int]\n :type size: int\n \"\"\"\n self.__nums = nums\n\n\n def reset(self):\n \"\"\"\n Resets the array to its original configuration and return it.\n :rtype: List[int]\n \"\"\"\n return self.__nums\n\n\n def shuffle(self):\n \"\"\"\n Returns a random shuffling of the array.\n :rtype: List[int]\n \"\"\"\n nums = list(self.__nums)\n for i in range(len(nums)):\n j = random.randint(i, len(nums)-1)\n nums[i], nums[j] = nums[j], nums[i]\n return nums\n\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9894", "name": "LeetCode 0385: Mini Parser"}{"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: Mini Parser (Difficulty: Medium)\nTags: String, Stack, Depth-First Search\n\nGiven a string s represents the serialization of a nested list, implement a parser to deserialize it and return the deserialized NestedInteger.\nEach element is either an integer or a list whose elements may also be integers or other lists.\n\nExample 1:\nInput: s = \"324\"\nOutput: 324\nExplanation: You should return a NestedInteger object which contains a single integer 324.\n\nExample 2:\nInput: s = \"[123,[456,[789]]]\"\nOutput: [123,[456,[789]]]\nExplanation: Return a NestedInteger object containing a nested list with 2 elements:\n1. An integer containing value 123.\n2. A nested list containing two elements:\n i. An integer containing value 456.\n ii. A nested list with one element:\n a. An integer containing value 789\n\nConstraints:\n- 1 <= s.length <= 5 * 10^4\n- s consists of digits, square brackets \"[]\", negative sign '-', and commas ','.\n- s is the serialization of valid NestedInteger.\n- All the values in the input are in the range [-106, 106]."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(h)\n\nclass NestedInteger(object):\n def __init__(self, value=None):\n \"\"\"\n If value is not specified, initializes an empty list.\n Otherwise initializes a single integer equal to value.\n \"\"\"\n\n def isInteger(self):\n \"\"\"\n @return True if this NestedInteger holds a single integer, rather than a nested list.\n :rtype bool\n \"\"\"\n\n def add(self, elem):\n \"\"\"\n Set this NestedInteger to hold a nested list and adds a nested integer elem to it.\n :rtype void\n \"\"\"\n\n def setInteger(self, value):\n \"\"\"\n Set this NestedInteger to hold a single integer equal to value.\n :rtype void\n \"\"\"\n\n def getInteger(self):\n \"\"\"\n @return the single integer that this NestedInteger holds, if it holds a single integer\n Return None if this NestedInteger holds a nested list\n :rtype int\n \"\"\"\n\n def getList(self):\n \"\"\"\n @return the nested list that this NestedInteger holds, if it holds a nested list\n Return None if this NestedInteger holds a single integer\n :rtype List[NestedInteger]\n \"\"\"\n\n\nclass Solution(object):\n def deserialize(self, s):\n if not s:\n return NestedInteger()\n\n if s[0] != '[':\n return NestedInteger(int(s))\n\n stk = []\n\n i = 0\n for j in range(len(s)):\n if s[j] == '[':\n stk += NestedInteger(),\n i = j+1\n elif s[j] in ',]':\n if s[j-1].isdigit():\n stk[-1].add(NestedInteger(int(s[i:j])))\n if s[j] == ']' and len(stk) > 1:\n cur = stk[-1]\n stk.pop()\n stk[-1].add(cur)\n i = j+1\n\n return stk[-1]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9895", "name": "LeetCode 0386: Lexicographical Numbers"}{"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: Lexicographical Numbers (Difficulty: Medium)\nTags: Depth-First Search, Trie\n\nGiven an integer n, return all the numbers in the range [1, n] sorted in lexicographical order.\nYou must write an algorithm that runs in O(n) time and uses O(1) extra space.\n\nExample 1:\nInput: n = 13\nOutput: [1,10,11,12,13,2,3,4,5,6,7,8,9]\n\nExample 2:\nInput: n = 2\nOutput: [1,2]\n\nConstraints:\n- 1 <= n <= 5 * 10^4"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def lexicalOrder(self, n):\n result = []\n\n i = 1\n while len(result) < n:\n k = 0\n while i * 10**k <= n:\n result.append(i * 10**k)\n k += 1\n\n num = result[-1] + 1\n while num <= n and num % 10:\n result.append(num)\n num += 1\n\n if not num % 10:\n num -= 1\n else:\n num /= 10\n\n while num % 10 == 9:\n num /= 10\n\n i = num+1\n\n return result\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9896", "name": "LeetCode 0387: First Unique Character In A String"}{"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: First Unique Character in a String (Difficulty: Easy)\nTags: Hash Table, String, Queue, Counting\n\nGiven a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1.\n\nExample 1:\nInput: s = \"leetcode\"\nOutput: 0\nExplanation:\nThe character 'l' at index 0 is the first character that does not occur at any other index.\n\nExample 2:\nInput: s = \"loveleetcode\"\nOutput: 2\n\nExample 3:\nInput: s = \"aabb\"\nOutput: -1\n\nConstraints:\n- 1 <= s.length <= 10^5\n- s consists of only lowercase English letters."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(n)\n\nfrom collections import defaultdict\n\nclass Solution(object):\n def firstUniqChar(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n lookup = defaultdict(int)\n candidtates = set()\n for i, c in enumerate(s):\n if lookup[c]:\n candidtates.discard(lookup[c])\n else:\n lookup[c] = i+1\n candidtates.add(i+1)\n\n return min(candidtates)-1 if candidtates else -1\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9897", "name": "LeetCode 0388: Longest Absolute File Path"}{"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: Longest Absolute File Path (Difficulty: Medium)\nTags: String, Stack, Depth-First Search\n\nSuppose we have a file system that stores both files and directories. An example of one system is represented in the following picture:\nHere, we have dir as the only directory in the root. dir contains two subdirectories, subdir1 and subdir2. subdir1 contains a file file1.ext and subdirectory subsubdir1. subdir2 contains a subdirectory subsubdir2, which contains a file file2.ext.\nIn text form, it looks like this (with ⟶ representing the tab character):\nIf we were to write this representation in code, it will look like this: \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\". Note that the '\\n' and '\\t' are the new-line and tab characters.\nEvery file and directory has a unique absolute path in the file system, which is the order of directories that must be opened to reach the file/directory itself, all concatenated by '/'s. Using the above example, the absolute path to file2.ext is \"dir/subdir2/subsubdir2/file2.ext\". Each directory name consists of letters, digits, and/or spaces. Each file name is of the form name.extension, where name and extension consist of letters, digits, and/or spaces.\nGiven a string input representing the file system in the explained format, return the length of the longest absolute path to a file in the abstracted file system. If there is no file in the system, return 0.\nNote that the testcases are generated such that the file system is valid and no file or directory name has length 0.\n\nExample 1:\ndir\n⟶ subdir1\n⟶ ⟶ file1.ext\n⟶ ⟶ subsubdir1\n⟶ subdir2\n⟶ ⟶ subsubdir2\n⟶ ⟶ ⟶ file2.ext\n\nExample 2:\nInput: input = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\"\nOutput: 20\nExplanation: We have only one file, and the absolute path is \"dir/subdir2/file.ext\" of length 20.\n\nExample 3:\nInput: input = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\"\nOutput: 32\nExplanation: We have two files:\n\"dir/subdir1/file1.ext\" of length 21\n\"dir/subdir2/subsubdir2/file2.ext\" of length 32.\nWe return 32 since it is the longest absolute path to a file.\n\nExample 4:\nInput: input = \"a\"\nOutput: 0\nExplanation: We do not have any files, just a single directory named \"a\".\n\nConstraints:\n- 1 <= input.length <= 10^4\n- input may contain lowercase or uppercase English letters, a new line character '\\n', a tab character '\\t', a dot '.', a space ' ', and digits.\n- All file and directory names have positive length."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(d), d is the max depth of the paths\n\nclass Solution(object):\n def lengthLongestPath(self, input):\n \"\"\"\n :type input: str\n :rtype: int\n \"\"\"\n def split_iter(s, tok):\n start = 0\n for i in range(len(s)):\n if s[i] == tok:\n yield s[start:i]\n start = i + 1\n yield s[start:]\n\n\n max_len = 0\n path_len = {0: 0}\n for line in split_iter(input, '\\n'):\n name = line.lstrip('\\t')\n depth = len(line) - len(name)\n if '.' in name:\n max_len = max(max_len, path_len[depth] + len(name))\n else:\n path_len[depth + 1] = path_len[depth] + len(name) + 1\n return max_len\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9898", "name": "LeetCode 0389: Find The Difference"}{"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: Find the Difference (Difficulty: Easy)\nTags: Hash Table, String, Bit Manipulation, Sorting\n\nYou are given two strings s and t.\nString t is generated by random shuffling string s and then add one more letter at a random position.\nReturn the letter that was added to t.\n\nExample 1:\nInput: s = \"abcd\", t = \"abcde\"\nOutput: \"e\"\nExplanation: 'e' is the letter that was added.\n\nExample 2:\nInput: s = \"\", t = \"y\"\nOutput: \"y\"\n\nConstraints:\n- 0 <= s.length <= 1000\n- t.length == s.length + 1\n- s and t consist of lowercase English letters."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nimport operator\nimport collections\nfrom functools import reduce\n\n\nclass Solution(object):\n def findTheDifference(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"\n return chr(reduce(operator.xor, map(ord, s), 0) ^ reduce(operator.xor, map(ord, t), 0))\n\n def findTheDifference2(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: str\n \"\"\"\n t = list(t)\n s = list(s)\n for i in s:\n t.remove(i)\n return t[0]\n\n def findTheDifference3(self, s, t):\n return chr(reduce(operator.xor, map(ord, s + t)))\n\n def findTheDifference4(self, s, t):\n return list((collections.Counter(t) - collections.Counter(s)))[0]\n\n def findTheDifference5(self, s, t):\n s, t = sorted(s), sorted(t)\n return t[-1] if s == t[:-1] else [x[1] for x in zip(s, t) if x[0] != x[1]][0]\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9899", "name": "LeetCode 0390: Elimination Game"}{"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: Elimination Game (Difficulty: Medium)\nTags: Math, Recursion\n\nYou have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr:\nGiven the integer n, return the last number that remains in arr.\n\nExample 1:\nInput: n = 9\nOutput: 6\nExplanation:\narr = [1, 2, 3, 4, 5, 6, 7, 8, 9]\narr = [2, 4, 6, 8]\narr = [2, 6]\narr = [6]\n\nExample 2:\nInput: n = 1\nOutput: 1\n\nConstraints:\n- 1 <= n <= 10^9"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(logn)\n# Space: O(1)\n\nclass Solution(object):\n def lastRemaining(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n start, step, direction = 1, 2, 1\n while n > 1:\n start += direction * (step * (n//2) - step//2)\n n //= 2\n step *= 2\n direction *= -1\n return start\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9900", "name": "LeetCode 0391: Perfect Rectangle"}{"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: Perfect Rectangle (Difficulty: Hard)\nTags: Array, Hash Table, Math, Geometry, Line Sweep\n\nGiven an array rectangles where rectangles[i] = [xi, yi, ai, bi] represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi) and the top-right point of it is (ai, bi).\nReturn true if all the rectangles together form an exact cover of a rectangular region.\n\nExample 1:\nInput: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]\nOutput: true\nExplanation: All 5 rectangles together form an exact cover of a rectangular region.\n\nExample 2:\nInput: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]\nOutput: false\nExplanation: Because there is a gap between the two rectangular regions.\n\nExample 3:\nInput: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]\nOutput: false\nExplanation: Because two of the rectangles overlap with each other.\n\nConstraints:\n- 1 <= rectangles.length <= 2 * 10^4\n- rectangles[i].length == 4\n- -10^5 <= xi < ai <= 10^5\n- -10^5 <= yi < bi <= 10^5"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(n)\n\nfrom collections import defaultdict\n\nclass Solution(object):\n def isRectangleCover(self, rectangles):\n \"\"\"\n :type rectangles: List[List[int]]\n :rtype: bool\n \"\"\"\n left = min(rec[0] for rec in rectangles)\n bottom = min(rec[1] for rec in rectangles)\n right = max(rec[2] for rec in rectangles)\n top = max(rec[3] for rec in rectangles)\n\n points = defaultdict(int)\n for l, b, r, t in rectangles:\n for p, q in zip(((l, b), (r, b), (l, t), (r, t)), (1, 2, 4, 8)):\n if points[p] & q:\n return False\n points[p] |= q\n\n for px, py in points:\n if left < px < right or bottom < py < top:\n if points[(px, py)] not in (3, 5, 10, 12, 15):\n return False\n\n return True\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9901", "name": "LeetCode 0392: Is Subsequence"}{"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: Is Subsequence (Difficulty: Easy)\nTags: Two Pointers, String, Dynamic Programming\n\nGiven two strings s and t, return true if s is a subsequence of t, or false otherwise.\nA subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters without disturbing the relative positions of the remaining characters. (i.e., \"ace\" is a subsequence of \"abcde\" while \"aec\" is not).\n\nExample 1:\nInput: s = \"abc\", t = \"ahbgdc\"\nOutput: true\n\nExample 2:\nInput: s = \"axc\", t = \"ahbgdc\"\nOutput: false\n\nConstraints:\n- 0 <= s.length <= 100\n- 0 <= t.length <= 10^4\n- s and t consist only of lowercase English letters."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def isSubsequence(self, s, t):\n \"\"\"\n :type s: str\n :type t: str\n :rtype: bool\n \"\"\"\n if not s:\n return True\n\n i = 0\n for c in t:\n if c == s[i]:\n i += 1\n if i == len(s):\n break\n return i == len(s)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9902", "name": "LeetCode 0393: Utf 8 Validation"}{"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: UTF-8 Validation (Difficulty: Medium)\nTags: Array, Bit Manipulation\n\nGiven an integer array data representing the data, return whether it is a valid UTF-8 encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters).\nA character in UTF8 can be from 1 to 4 bytes long, subjected to the following rules:\nThis is how the UTF-8 encoding would work:\nx denotes a bit in the binary form of a byte that may be either 0 or 1.\nNote: The input is an array of integers. Only the least significant 8 bits of each integer is used to store the data. This means each integer represents only 1 byte of data.\n\nExample 1:\nNumber of Bytes | UTF-8 Octet Sequence\n | (binary)\n --------------------+-----------------------------------------\n 1 | 0xxxxxxx\n 2 | 110xxxxx 10xxxxxx\n 3 | 1110xxxx 10xxxxxx 10xxxxxx\n 4 | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx\n\nExample 2:\nInput: data = [197,130,1]\nOutput: true\nExplanation: data represents the octet sequence: 11000101 10000010 00000001.\nIt is a valid utf-8 encoding for a 2-bytes character followed by a 1-byte character.\n\nExample 3:\nInput: data = [235,140,4]\nOutput: false\nExplanation: data represented the octet sequence: 11101011 10001100 00000100.\nThe first 3 bits are all one's and the 4th bit is 0 means it is a 3-bytes character.\nThe next byte is a continuation byte which starts with 10 and that's correct.\nBut the second continuation byte does not start with 10, so it is invalid.\n\nConstraints:\n- 1 <= data.length <= 2 * 10^4\n- 0 <= data[i] <= 255"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def validUtf8(self, data):\n \"\"\"\n :type data: List[int]\n :rtype: bool\n \"\"\"\n count = 0\n for c in data:\n if count == 0:\n if (c >> 5) == 0b110:\n count = 1\n elif (c >> 4) == 0b1110:\n count = 2\n elif (c >> 3) == 0b11110:\n count = 3\n elif (c >> 7):\n return False\n else:\n if (c >> 6) != 0b10:\n return False\n count -= 1\n return count == 0\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9903", "name": "LeetCode 0394: Decode String"}{"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: Decode String (Difficulty: Medium)\nTags: String, Stack, Recursion\n\nGiven an encoded string, return its decoded string.\nThe encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.\nYou may assume that the input string is always valid; there are no extra white spaces, square brackets are well-formed, etc. Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there will not be input like 3a or 2[4].\nThe test cases are generated so that the length of the output will never exceed 105.\n\nExample 1:\nInput: s = \"3[a]2[bc]\"\nOutput: \"aaabcbc\"\n\nExample 2:\nInput: s = \"3[a2[c]]\"\nOutput: \"accaccacc\"\n\nExample 3:\nInput: s = \"2[abc]3[cd]ef\"\nOutput: \"abcabccdcdcdef\"\n\nConstraints:\n- 1 <= s.length <= 30\n- s consists of lowercase English letters, digits, and square brackets '[]'.\n- s is guaranteed to be a valid input.\n- All the integers in s are in the range [1, 300]."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(n)\n\nclass Solution(object):\n def decodeString(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n n, curr, nums, strs = 0, [], [], []\n for c in s:\n if c.isdigit():\n n = n*10 + ord(c)-ord('0')\n elif c.isalpha():\n curr.append(c)\n elif c == '[':\n nums.append(n)\n strs.append(curr)\n n, curr = 0, []\n elif c == ']':\n strs[-1].extend(curr*nums.pop())\n curr = strs.pop()\n return \"\".join(curr)\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9904", "name": "LeetCode 0395: Longest Substring With At Least K Repeating Characters"}{"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: Longest Substring with At Least K Repeating Characters (Difficulty: Medium)\nTags: Hash Table, String, Divide and Conquer, Sliding Window\n\nGiven a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.\nif no such substring exists, return 0.\n\nExample 1:\nInput: s = \"aaabb\", k = 3\nOutput: 3\nExplanation: The longest substring is \"aaa\", as 'a' is repeated 3 times.\n\nExample 2:\nInput: s = \"ababbc\", k = 2\nOutput: 5\nExplanation: The longest substring is \"ababb\", as 'a' is repeated 2 times and 'b' is repeated 3 times.\n\nConstraints:\n- 1 <= s.length <= 10^4\n- s consists of only lowercase English letters.\n- 1 <= k <= 10^5"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(26 * n) = O(n)\n# Space: O(26) = O(1)\n\nclass Solution(object):\n def longestSubstring(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n def longestSubstringHelper(s, k, start, end):\n count = [0] * 26\n for i in range(start, end):\n count[ord(s[i]) - ord('a')] += 1\n max_len = 0\n i = start\n while i < end:\n while i < end and count[ord(s[i]) - ord('a')] < k:\n i += 1\n j = i\n while j < end and count[ord(s[j]) - ord('a')] >= k:\n j += 1\n\n if i == start and j == end:\n return end - start\n\n max_len = max(max_len, longestSubstringHelper(s, k, i, j))\n i = j\n return max_len\n\n return longestSubstringHelper(s, k, 0, len(s))\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9905", "name": "LeetCode 0396: Rotate Function"}{"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: Rotate Function (Difficulty: Medium)\nTags: Array, Math, Dynamic Programming\n\nYou are given an integer array nums of length n.\nAssume arrk to be an array obtained by rotating nums by k positions clock-wise. We define the rotation function F on nums as follow:\nReturn the maximum value of F(0), F(1), ..., F(n-1).\nThe test cases are generated so that the answer fits in a 32-bit integer.\n\nExample 1:\nInput: nums = [4,3,2,6]\nOutput: 26\nExplanation:\nF(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25\nF(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16\nF(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23\nF(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26\nSo the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.\n\nExample 2:\nInput: nums = [100]\nOutput: 0\n\nConstraints:\n- n == nums.length\n- 1 <= n <= 10^5\n- -100 <= nums[i] <= 100"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def maxRotateFunction(self, A):\n \"\"\"\n :type A: List[int]\n :rtype: int\n \"\"\"\n s = sum(A)\n fi = 0\n for i in range(len(A)):\n fi += i * A[i]\n\n result = fi\n for i in range(1, len(A)+1):\n fi += s - len(A) * A[-i]\n result = max(result, fi)\n return result\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9906", "name": "LeetCode 0397: Integer Replacement"}{"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: Integer Replacement (Difficulty: Medium)\nTags: Dynamic Programming, Greedy, Bit Manipulation, Memoization\n\nGiven a positive integer n, you can apply one of the following operations:\nReturn the minimum number of operations needed for n to become 1.\n\nExample 1:\nInput: n = 8\nOutput: 3\nExplanation: 8 -> 4 -> 2 -> 1\n\nExample 2:\nInput: n = 7\nOutput: 4\nExplanation: 7 -> 8 -> 4 -> 2 -> 1\nor 7 -> 6 -> 3 -> 2 -> 1\n\nExample 3:\nInput: n = 4\nOutput: 2\n\nConstraints:\n- 1 <= n <= 2^31 - 1"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(logn)\n# Space: O(1)\n\nclass Solution(object):\n def integerReplacement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n result = 0\n while n != 1:\n b = n & 3\n if n == 3:\n n -= 1\n elif b == 3:\n n += 1\n elif b == 1:\n n -= 1\n else:\n n /= 2\n result += 1\n\n return result\n\n\n# Time: O(logn)\n# Space: O(logn)\n# Recursive solution.\nclass Solution2(object):\n def integerReplacement(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n if n < 4:\n return [0, 0, 1, 2][n]\n if n % 4 in (0, 2):\n return self.integerReplacement(n / 2) + 1\n elif n % 4 == 1:\n return self.integerReplacement((n - 1) / 4) + 3\n else:\n return self.integerReplacement((n + 1) / 4) + 3\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9907", "name": "LeetCode 0398: Random Pick Index"}{"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: Random Pick Index (Difficulty: Medium)\nTags: Hash Table, Math, Reservoir Sampling, Randomized\n\nGiven an integer array nums with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.\nImplement the Solution class:\n\nExample 1:\nInput\n[\"Solution\", \"pick\", \"pick\", \"pick\"]\n[[[1, 2, 3, 3, 3]], [3], [1], [3]]\nOutput\n[null, 4, 0, 2]\n\nExplanation\nSolution solution = new Solution([1, 2, 3, 3, 3]);\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\nsolution.pick(1); // It should return 0. Since in the array only nums[0] is equal to 1.\nsolution.pick(3); // It should return either index 2, 3, or 4 randomly. Each index should have equal probability of returning.\n\nConstraints:\n- 1 <= nums.length <= 2 * 10^4\n- -2^31 <= nums[i] <= 2^31 - 1\n- target is an integer from nums.\n- At most 104 calls will be made to pick."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: ctor: O(n)\n# pick: O(1)\n# Space: O(n)\n\nfrom random import randint\nimport collections\n\n\nclass Solution(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n self.__lookup = collections.defaultdict(list)\n for i, x in enumerate(nums):\n self.__lookup[x].append(i)\n\n def pick(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n return self.__lookup[target][randint(0, len(self.__lookup[target])-1)]\n\n\n# Time: ctor: O(1)\n# pick: O(n)\n# Space: O(1)\nfrom random import randint\n\n\nclass Solution_TLE(object):\n\n def __init__(self, nums):\n \"\"\"\n :type nums: List[int]\n \"\"\"\n self.__nums = nums\n\n def pick(self, target):\n \"\"\"\n :type target: int\n :rtype: int\n \"\"\"\n reservoir = -1\n n = 0\n for i in range(len(self.__nums)):\n if self.__nums[i] != target:\n continue\n reservoir = i if randint(1, n+1) == 1 else reservoir\n n += 1\n return reservoir\n\n\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9908", "name": "LeetCode 0399: Evaluate Division"}{"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: Evaluate Division (Difficulty: Medium)\nTags: Array, String, Depth-First Search, Breadth-First Search, Union Find, Graph, Shortest Path\n\nYou are given an array of variable pairs equations and an array of real numbers values, where equations[i] = [Ai, Bi] and values[i] represent the equation Ai / Bi = values[i]. Each Ai or Bi is a string that represents a single variable.\nYou are also given some queries, where queries[j] = [Cj, Dj] represents the jth query where you must find the answer for Cj / Dj = ?.\nReturn the answers to all queries. If a single answer cannot be determined, return -1.0.\nNote: The input is always valid. You may assume that evaluating the queries will not result in division by zero and that there is no contradiction.\nNote: The variables that do not occur in the list of equations are undefined, so the answer cannot be determined for them.\n\nExample 1:\nInput: equations = [[\"a\",\"b\"],[\"b\",\"c\"]], values = [2.0,3.0], queries = [[\"a\",\"c\"],[\"b\",\"a\"],[\"a\",\"e\"],[\"a\",\"a\"],[\"x\",\"x\"]]\nOutput: [6.00000,0.50000,-1.00000,1.00000,-1.00000]\nExplanation: \nGiven: a / b = 2.0, b / c = 3.0\nqueries are: a / c = ?, b / a = ?, a / e = ?, a / a = ?, x / x = ? \nreturn: [6.0, 0.5, -1.0, 1.0, -1.0 ]\nnote: x is undefined => -1.0\n\nExample 2:\nInput: equations = [[\"a\",\"b\"],[\"b\",\"c\"],[\"bc\",\"cd\"]], values = [1.5,2.5,5.0], queries = [[\"a\",\"c\"],[\"c\",\"b\"],[\"bc\",\"cd\"],[\"cd\",\"bc\"]]\nOutput: [3.75000,0.40000,5.00000,0.20000]\n\nExample 3:\nInput: equations = [[\"a\",\"b\"]], values = [0.5], queries = [[\"a\",\"b\"],[\"b\",\"a\"],[\"a\",\"c\"],[\"x\",\"y\"]]\nOutput: [0.50000,2.00000,-1.00000,-1.00000]\n\nConstraints:\n- 1 <= equations.length <= 20\n- equations[i].length == 2\n- 1 <= Ai.length, Bi.length <= 5\n- values.length == equations.length\n- 0.0 < values[i] <= 20.0\n- 1 <= queries.length <= 20\n- queries[i].length == 2\n- 1 <= Cj.length, Dj.length <= 5\n- Ai, Bi, Cj, Dj consist of lower case English letters and digits."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O((e + q) * α(n)) ~= O(e + q), using either one of \"path compression\" and \"union by rank\" results in amortized O(logn)\n# , using both results in α(n) ~= O(1)\n# Space: O(n)\n\nimport collections\nimport itertools\n\n\nclass UnionFind(object):\n def __init__(self):\n self.set = {}\n self.rank = collections.Counter()\n\n def find_set(self, x):\n xp, xr = self.set.setdefault(x, (x, 1.0))\n if x != xp:\n pp, pr = self.find_set(xp) # path compression.\n self.set[x] = (pp, xr*pr) # x/pp = xr*pr\n return self.set[x]\n\n def union_set(self, x, y, r):\n (xp, xr), (yp, yr) = map(self.find_set, (x, y))\n if xp == yp:\n return False\n if self.rank[xp] < self.rank[yp]: # union by rank\n # to make x/yp = r*yr and merge xp into yp\n # => since x/xp = xr, we can merge with xp/yp = r*yr/xr \n self.set[xp] = (yp, r*yr/xr)\n elif self.rank[xp] > self.rank[yp]:\n # to make y/xp = 1/r*xr and merge xp into yp\n # => since y/yp = yr, we can merge with yp/xp = 1/r*xr/yr \n self.set[yp] = (xp, 1.0/r*xr/yr)\n else:\n # to make y/xp = 1/r*xr and merge xp into yp\n # => since y/yp = yr, we can merge with yp/xp = 1/r*xr/yr \n self.set[yp] = (xp, 1.0/r*xr/yr)\n self.rank[xp] += 1 \n return True\n\n def query_set(self, x, y):\n if x not in self.set or y not in self.set:\n return -1.0\n (xp, xr), (yp, yr) = map(self.find_set, (x, y))\n return xr/yr if xp == yp else -1.0\n\n\nclass UnionFindPathCompressionOnly(object):\n def __init__(self):\n self.set = {}\n\n def find_set(self, x):\n xp, xr = self.set.setdefault(x, (x, 1.0))\n if x != xp:\n pp, pr = self.find_set(xp) # path compression.\n self.set[x] = (pp, xr*pr) # x/pp = xr*pr\n return self.set[x]\n\n def union_set(self, x, y, r):\n (xp, xr), (yp, yr) = map(self.find_set, (x, y))\n if xp == yp:\n return False\n # to make x/yp = r*yr and merge xp into yp\n # => since x/xp = xr, we can merge with xp/yp = r*yr/xr \n self.set[xp] = (yp, r*yr/xr)\n return True\n\n def query_set(self, x, y):\n if x not in self.set or y not in self.set:\n return -1.0\n (xp, xr), (yp, yr) = map(self.find_set, (x, y))\n return xr/yr if xp == yp else -1.0\n\n\nclass Solution(object):\n def calcEquation(self, equations, values, queries):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type queries: List[List[str]]\n :rtype: List[float]\n \"\"\"\n union_find = UnionFind()\n for (a, b), k in itertools.izip(equations, values):\n union_find.union_set(a, b, k)\n return [union_find.query_set(a, b) for a, b in queries]\n\n\n# Time: O(e + q * n), at most O(n^3 + q)\n# Space: O(n^2)\n# bfs solution\nimport collections\nimport itertools\n\n\nclass Solution2(object):\n def calcEquation(self, equations, values, queries):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type queries: List[List[str]]\n :rtype: List[float]\n \"\"\"\n adj = collections.defaultdict(dict)\n for (a, b), k in itertools.izip(equations, values):\n adj[a][b] = k\n adj[b][a] = 1.0/k\n\n def bfs(adj, a, b, lookup):\n if a not in adj or b not in adj:\n return -1.0\n if (a, b) in lookup:\n return lookup[a, b]\n visited = {a}\n q = collections.deque([(a, 1.0)])\n while q:\n u, val = q.popleft()\n if u == b:\n lookup[a, b] = val\n return val\n for v, k in adj[u].iteritems():\n if v in visited:\n continue \n visited.add(v)\n q.append((v, val*k))\n lookup[a, b] = -1.0\n return -1.0\n\n lookup = {}\n return [bfs(adj, a, b, lookup) for a, b in queries]\n\n\n# Time: O(n^3 + q)\n# Space: O(n^2)\nimport collections\nimport itertools\n\n\n# variant of floyd–warshall algorithm solution\nclass Solution3(object):\n def calcEquation(self, equations, values, queries):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type queries: List[List[str]]\n :rtype: List[float]\n \"\"\"\n adj = collections.defaultdict(dict)\n for (a, b), k in itertools.izip(equations, values):\n adj[a][a] = adj[b][b] = 1.0\n adj[a][b] = k\n adj[b][a] = 1.0/k\n for k in adj:\n for i in adj[k]:\n for j in adj[k]:\n adj[i][j] = adj[i][k]*adj[k][j]\n return [adj[a].get(b, -1.0) for a, b in queries]\n\n \n# Time: O(e + q * n), at most O(n^3 + q)\n# Space: O(e)\nimport collections\n\n\nclass Solution4(object):\n def calcEquation(self, equations, values, query):\n \"\"\"\n :type equations: List[List[str]]\n :type values: List[float]\n :type query: List[List[str]]\n :rtype: List[float]\n \"\"\"\n def check(up, down, lookup, visited):\n if up in lookup and down in lookup[up]:\n return (True, lookup[up][down])\n for k, v in lookup[up].iteritems():\n if k not in visited:\n visited.add(k)\n tmp = check(k, down, lookup, visited)\n if tmp[0]:\n return (True, v * tmp[1])\n return (False, 0)\n\n lookup = collections.defaultdict(dict)\n for i, e in enumerate(equations):\n lookup[e[0]][e[1]] = values[i]\n if values[i]:\n lookup[e[1]][e[0]] = 1.0 / values[i]\n\n result = []\n for q in query:\n visited = set()\n tmp = check(q[0], q[1], lookup, visited)\n result.append(tmp[1] if tmp[0] else -1)\n return result\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9909", "name": "LeetCode 0400: Nth Digit"}{"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: Nth Digit (Difficulty: Medium)\nTags: Math, Binary Search\n\nGiven an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].\n\nExample 1:\nInput: n = 3\nOutput: 3\n\nExample 2:\nInput: n = 11\nOutput: 0\nExplanation: The 11th digit of the sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... is a 0, which is part of the number 10.\n\nConstraints:\n- 1 <= n <= 2^31 - 1"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(logn)\n# Space: O(1)\n\nclass Solution(object):\n def findNthDigit(self, n):\n \"\"\"\n :type n: int\n :rtype: int\n \"\"\"\n digit_len = 1\n while n > digit_len * 9 * (10 ** (digit_len-1)):\n n -= digit_len * 9 * (10 ** (digit_len-1))\n digit_len += 1\n\n num = 10 ** (digit_len-1) + (n-1)/digit_len\n\n nth_digit = num / (10 ** ((digit_len-1) - ((n-1)%digit_len)))\n nth_digit %= 10\n\n return nth_digit\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9910", "name": "LeetCode 0401: Binary Watch"}{"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: Binary Watch (Difficulty: Easy)\nTags: Backtracking, Bit Manipulation\n\nA binary watch has 4 LEDs on the top to represent the hours (0-11), and 6 LEDs on the bottom to represent the minutes (0-59). Each LED represents a zero or one, with the least significant bit on the right.\nGiven an integer turnedOn which represents the number of LEDs that are currently on (ignoring the PM), return all possible times the watch could represent. You may return the answer in any order.\nThe hour must not contain a leading zero.\nThe minute must consist of two digits and may contain a leading zero.\n\nExample 1:\nInput: turnedOn = 1\nOutput: [\"0:01\",\"0:02\",\"0:04\",\"0:08\",\"0:16\",\"0:32\",\"1:00\",\"2:00\",\"4:00\",\"8:00\"]\n\nExample 2:\nInput: turnedOn = 9\nOutput: []\n\nConstraints:\n- 0 <= turnedOn <= 10"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(1)\n# Space: O(1)\n\n\nclass Solution(object):\n def readBinaryWatch(self, num):\n \"\"\"\n :type num: int\n :rtype: List[str]\n \"\"\"\n def bit_count(bits):\n count = 0\n while bits:\n bits &= bits-1\n count += 1\n return count\n\n return ['%d:%02d' % (h, m) for h in range(12) for m in range(60)\n if bit_count(h) + bit_count(m) == num]\n\n def readBinaryWatch2(self, num):\n \"\"\"\n :type num: int\n :rtype: List[str]\n \"\"\"\n return ['{0}:{1}'.format(str(h), str(m).zfill(2))\n for h in range(12) for m in range(60)\n if (bin(h) + bin(m)).count('1') == num]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9911", "name": "LeetCode 0402: Remove K Digits"}{"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 K Digits (Difficulty: Medium)\nTags: String, Stack, Greedy, Monotonic Stack\n\nGiven string num representing a non-negative integer num, and an integer k, return the smallest possible integer after removing k digits from num.\n\nExample 1:\nInput: num = \"1432219\", k = 3\nOutput: \"1219\"\nExplanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.\n\nExample 2:\nInput: num = \"10200\", k = 1\nOutput: \"200\"\nExplanation: Remove the leading 1 and the number is 200. Note that the output must not contain leading zeroes.\n\nExample 3:\nInput: num = \"10\", k = 2\nOutput: \"0\"\nExplanation: Remove all the digits from the number and it is left with nothing which is 0.\n\nConstraints:\n- 1 <= k <= num.length <= 10^5\n- num consists of only digits.\n- num does not have any leading zeros except for the zero itself."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(n)\n\nclass Solution(object):\n def removeKdigits(self, num, k):\n \"\"\"\n :type num: str\n :type k: int\n :rtype: str\n \"\"\"\n result = []\n for d in num:\n while k and result and result[-1] > d:\n result.pop()\n k -= 1\n result.append(d)\n return ''.join(result).lstrip('0')[:-k or None] or '0'\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9912", "name": "LeetCode 0403: Frog Jump"}{"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: Frog Jump (Difficulty: Hard)\nTags: Array, Dynamic Programming\n\nA frog is crossing a river. The river is divided into some number of units, and at each unit, there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.\nGiven a list of stones positions (in units) in sorted ascending order, determine if the frog can cross the river by landing on the last stone. Initially, the frog is on the first stone and assumes the first jump must be 1 unit.\nIf the frog's last jump was k units, its next jump must be either k - 1, k, or k + 1 units. The frog can only jump in the forward direction.\n\nExample 1:\nInput: stones = [0,1,3,5,6,8,12,17]\nOutput: true\nExplanation: The frog can jump to the last stone by jumping 1 unit to the 2nd stone, then 2 units to the 3rd stone, then 2 units to the 4th stone, then 3 units to the 6th stone, 4 units to the 7th stone, and 5 units to the 8th stone.\n\nExample 2:\nInput: stones = [0,1,2,3,4,8,9,11]\nOutput: false\nExplanation: There is no way to jump to the last stone as the gap between the 5th and 6th stone is too large.\n\nConstraints:\n- 2 <= stones.length <= 2000\n- 0 <= stones[i] <= 2^31 - 1\n- stones[0] == 0\n- stones is sorted in a strictly increasing order."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n^2)\n# Space: O(n^2)\n\nclass Solution(object):\n def canCross(self, stones):\n \"\"\"\n :type stones: List[int]\n :rtype: bool\n \"\"\"\n if stones[1] != 1:\n return False\n\n last_jump_units = {s: set() for s in stones}\n last_jump_units[1].add(1)\n for s in stones[:-1]:\n for j in last_jump_units[s]:\n for k in (j-1, j, j+1):\n if k > 0 and s+k in last_jump_units:\n last_jump_units[s+k].add(k)\n return bool(last_jump_units[stones[-1]])\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9913", "name": "LeetCode 0404: Sum Of Left Leaves"}{"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: Sum of Left Leaves (Difficulty: Easy)\nTags: Tree, Depth-First Search, Breadth-First Search, Binary Tree\n\nGiven the root of a binary tree, return the sum of all left leaves.\nA leaf is a node with no children. A left leaf is a leaf that is the left child of another node.\n\nExample 1:\nInput: root = [3,9,20,null,null,15,7]\nOutput: 24\nExplanation: There are two left leaves in the binary tree, with values 9 and 15 respectively.\n\nExample 2:\nInput: root = [1]\nOutput: 0\n\nConstraints:\n- The number of nodes in the tree is in the range [1, 1000].\n- -1000 <= Node.val <= 1000"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(h)\n\nclass Solution(object):\n def sumOfLeftLeaves(self, root):\n \"\"\"\n :type root: TreeNode\n :rtype: int\n \"\"\"\n def sumOfLeftLeavesHelper(root, is_left):\n if not root:\n return 0\n if not root.left and not root.right:\n return root.val if is_left else 0\n return sumOfLeftLeavesHelper(root.left, True) + \\\n sumOfLeftLeavesHelper(root.right, False)\n\n return sumOfLeftLeavesHelper(root, False)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9914", "name": "LeetCode 0405: Convert A Number To Hexadecimal"}{"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: Convert a Number to Hexadecimal (Difficulty: Easy)\nTags: Math, String, Bit Manipulation\n\nGiven a 32-bit integer num, return a string representing its hexadecimal representation. For negative integers, two’s complement method is used.\nAll the letters in the answer string should be lowercase characters, and there should not be any leading zeros in the answer except for the zero itself.\nNote: You are not allowed to use any built-in library method to directly solve this problem.\n\nExample 1:\nInput: num = 26\nOutput: \"1a\"\n\nExample 2:\nInput: num = -1\nOutput: \"ffffffff\"\n\nConstraints:\n- -2^31 <= num <= 2^31 - 1"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(logn)\n# Space: O(1)\n\nclass Solution(object):\n def toHex(self, num):\n \"\"\"\n :type num: int\n :rtype: str\n \"\"\"\n if not num:\n return \"0\"\n\n result = []\n while num and len(result) != 8:\n h = num & 15\n if h < 10:\n result.append(str(chr(ord('0') + h)))\n else:\n result.append(str(chr(ord('a') + h-10)))\n num >>= 4\n result.reverse()\n\n return \"\".join(result)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9915", "name": "LeetCode 0406: Queue Reconstruction By Height"}{"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: Queue Reconstruction by Height (Difficulty: Medium)\nTags: Array, Binary Indexed Tree, Segment Tree, Sorting\n\nYou are given an array of people, people, which are the attributes of some people in a queue (not necessarily in order). Each people[i] = [hi, ki] represents the ith person of height hi with exactly ki other people in front who have a height greater than or equal to hi.\nReconstruct and return the queue that is represented by the input array people. The returned queue should be formatted as an array queue, where queue[j] = [hj, kj] is the attributes of the jth person in the queue (queue[0] is the person at the front of the queue).\n\nExample 1:\nInput: people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]]\nOutput: [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]]\nExplanation:\nPerson 0 has height 5 with no other people taller or the same height in front.\nPerson 1 has height 7 with no other people taller or the same height in front.\nPerson 2 has height 5 with two persons taller or the same height in front, which is person 0 and 1.\nPerson 3 has height 6 with one person taller or the same height in front, which is person 1.\nPerson 4 has height 4 with four people taller or the same height in front, which are people 0, 1, 2, and 3.\nPerson 5 has height 7 with one person taller or the same height in front, which is person 1.\nHence [[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] is the reconstructed queue.\n\nExample 2:\nInput: people = [[6,0],[5,0],[4,0],[3,2],[2,2],[1,4]]\nOutput: [[4,0],[5,0],[2,2],[3,2],[1,4],[6,0]]\n\nConstraints:\n- 1 <= people.length <= 2000\n- 0 <= hi <= 10^6\n- 0 <= ki < people.length\n- It is guaranteed that the queue can be reconstructed."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n * sqrt(n))\n# Space: O(n)\n\nclass Solution(object):\n def reconstructQueue(self, people):\n \"\"\"\n :type people: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n people.sort(key=lambda h_k: (-h_k[0], h_k[1]))\n\n blocks = [[]]\n for p in people:\n index = p[1]\n\n for i, block in enumerate(blocks):\n if index <= len(block):\n break\n index -= len(block)\n block.insert(index, p)\n\n if len(block) * len(block) > len(people):\n blocks.insert(i+1, block[len(block)/2:])\n del block[len(block)/2:]\n\n return [p for block in blocks for p in block]\n\n\n# Time: O(n^2)\n# Space: O(n)\nclass Solution2(object):\n def reconstructQueue(self, people):\n \"\"\"\n :type people: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n people.sort(key=lambda h_k1: (-h_k1[0], h_k1[1]))\n result = []\n for p in people:\n result.insert(p[1], p)\n return result\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9916", "name": "LeetCode 0407: Trapping Rain Water Ii"}{"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: Trapping Rain Water II (Difficulty: Hard)\nTags: Array, Breadth-First Search, Heap (Priority Queue), Matrix\n\nGiven an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.\n\nExample 1:\nInput: heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]\nOutput: 4\nExplanation: After the rain, water is trapped between the blocks.\nWe have two small ponds 1 and 3 units trapped.\nThe total volume of water trapped is 4.\n\nExample 2:\nInput: heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]\nOutput: 10\n\nConstraints:\n- m == heightMap.length\n- n == heightMap[i].length\n- 1 <= m, n <= 200\n- 0 <= heightMap[i][j] <= 2 * 10^4"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(m * n * log(m + n)) ~ O(m * n * log(m * n))\n# Space: O(m * n)\n\nfrom heapq import heappush, heappop\n\nclass Solution(object):\n def trapRainWater(self, heightMap):\n \"\"\"\n :type heightMap: List[List[int]]\n :rtype: int\n \"\"\"\n m = len(heightMap)\n if not m:\n return 0\n n = len(heightMap[0])\n if not n:\n return 0\n\n is_visited = [[False for i in range(n)] for j in range(m)]\n\n heap = []\n for i in range(m):\n heappush(heap, [heightMap[i][0], i, 0])\n is_visited[i][0] = True\n heappush(heap, [heightMap[i][n-1], i, n-1])\n is_visited[i][n-1] = True\n for j in range(1, n-1):\n heappush(heap, [heightMap[0][j], 0, j])\n is_visited[0][j] = True\n heappush(heap, [heightMap[m-1][j], m-1, j])\n is_visited[m-1][j] = True\n\n trap = 0\n while heap:\n height, i, j = heappop(heap)\n for (dx, dy) in [(1,0), (-1,0), (0,1), (0,-1)]:\n x, y = i+dx, j+dy\n if 0 <= x < m and 0 <= y < n and not is_visited[x][y]:\n trap += max(0, height - heightMap[x][y])\n heappush(heap, [max(height, heightMap[x][y]), x, y])\n is_visited[x][y] = True\n\n return trap\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9918", "name": "LeetCode 0409: Longest Palindrome"}{"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: Longest Palindrome (Difficulty: Easy)\nTags: Hash Table, String, Greedy\n\nGiven a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters.\nLetters are case sensitive, for example, \"Aa\" is not considered a palindrome.\n\nExample 1:\nInput: s = \"abccccdd\"\nOutput: 7\nExplanation: One longest palindrome that can be built is \"dccaccd\", whose length is 7.\n\nExample 2:\nInput: s = \"a\"\nOutput: 1\nExplanation: The longest palindrome that can be built is \"a\", whose length is 1.\n\nConstraints:\n- 1 <= s.length <= 2000\n- s consists of lowercase and/or uppercase English letters only."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nimport collections\n\n\nclass Solution(object):\n def longestPalindrome(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n odds = 0\n for k, v in collections.Counter(s).iteritems():\n odds += v & 1\n return len(s) - odds + int(odds > 0)\n\n def longestPalindrome2(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n odd = sum(map(lambda x: x & 1, collections.Counter(s).values()))\n return len(s) - odd + int(odd > 0)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9919", "name": "LeetCode 0410: Split Array Largest Sum"}{"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: Split Array Largest Sum (Difficulty: Hard)\nTags: Array, Binary Search, Dynamic Programming, Greedy, Prefix Sum\n\nGiven an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.\nReturn the minimized largest sum of the split.\nA subarray is a contiguous part of the array.\n\nExample 1:\nInput: nums = [7,2,5,10,8], k = 2\nOutput: 18\nExplanation: There are four ways to split nums into two subarrays.\nThe best way is to split it into [7,2,5] and [10,8], where the largest sum among the two subarrays is only 18.\n\nExample 2:\nInput: nums = [1,2,3,4,5], k = 2\nOutput: 9\nExplanation: There are four ways to split nums into two subarrays.\nThe best way is to split it into [1,2,3] and [4,5], where the largest sum among the two subarrays is only 9.\n\nConstraints:\n- 1 <= nums.length <= 1000\n- 0 <= nums[i] <= 10^6\n- 1 <= k <= min(50, nums.length)"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(nlogs), s is the sum of nums\n# Space: O(1)\n\nclass Solution(object):\n def splitArray(self, nums, m):\n \"\"\"\n :type nums: List[int]\n :type m: int\n :rtype: int\n \"\"\"\n def check(nums, m, s):\n cnt, curr_sum = 1, 0\n for num in nums:\n curr_sum += num\n if curr_sum > s:\n curr_sum = num\n cnt += 1\n return cnt <= m\n\n left, right = max(nums), sum(nums)\n while left <= right:\n mid = left + (right - left) // 2\n if check(nums, m, mid):\n right = mid - 1\n else:\n left = mid + 1\n return left\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9921", "name": "LeetCode 0412: Fizz Buzz"}{"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: Fizz Buzz (Difficulty: Easy)\nTags: Math, String, Simulation\n\nGiven an integer n, return a string array answer (1-indexed) where:\n\nExample 1:\nInput: n = 3\nOutput: [\"1\",\"2\",\"Fizz\"]\n\nExample 2:\nInput: n = 5\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n\nExample 3:\nInput: n = 15\nOutput: [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n\nConstraints:\n- 1 <= n <= 10^4"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def fizzBuzz(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"\n result = []\n\n for i in range(1, n+1):\n if i % 15 == 0:\n result.append(\"FizzBuzz\")\n elif i % 5 == 0:\n result.append(\"Buzz\")\n elif i % 3 == 0:\n result.append(\"Fizz\")\n else:\n result.append(str(i))\n\n return result\n\n def fizzBuzz2(self, n):\n \"\"\"\n :type n: int\n :rtype: List[str]\n \"\"\"\n l = [str(x) for x in range(n + 1)]\n l3 = range(0, n + 1, 3)\n l5 = range(0, n + 1, 5)\n for i in l3:\n l[i] = 'Fizz'\n for i in l5:\n if l[i] == 'Fizz':\n l[i] += 'Buzz'\n else:\n l[i] = 'Buzz'\n return l[1:]\n\n def fizzBuzz3(self, n):\n return ['Fizz' * (not i % 3) + 'Buzz' * (not i % 5) or str(i) for i in range(1, n + 1)]\n\n def fizzBuzz4(self, n):\n return ['FizzBuzz'[i % -3 & -4:i % -5 & 8 ^ 12] or repr(i) for i in range(1, n + 1)]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9922", "name": "LeetCode 0413: Arithmetic Slices"}{"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: Arithmetic Slices (Difficulty: Medium)\nTags: Array, Dynamic Programming, Sliding Window\n\nAn integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.\nGiven an integer array nums, return the number of arithmetic subarrays of nums.\nA subarray is a contiguous subsequence of the array.\n\nExample 1:\nInput: nums = [1,2,3,4]\nOutput: 3\nExplanation: We have 3 arithmetic slices in nums: [1, 2, 3], [2, 3, 4] and [1,2,3,4] itself.\n\nExample 2:\nInput: nums = [1]\nOutput: 0\n\nConstraints:\n- 1 <= nums.length <= 5000\n- -1000 <= nums[i] <= 1000"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def numberOfArithmeticSlices(self, A):\n \"\"\"\n :type A: List[int]\n :rtype: int\n \"\"\"\n res, i = 0, 0\n while i+2 < len(A):\n start = i\n while i+2 < len(A) and A[i+2] + A[i] == 2*A[i+1]:\n res += i - start + 1\n i += 1\n i += 1\n\n return res\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9923", "name": "LeetCode 0414: Third Maximum Number"}{"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: Third Maximum Number (Difficulty: Easy)\nTags: Array, Sorting\n\nGiven an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.\n\nExample 1:\nInput: nums = [3,2,1]\nOutput: 1\nExplanation:\nThe first distinct maximum is 3.\nThe second distinct maximum is 2.\nThe third distinct maximum is 1.\n\nExample 2:\nInput: nums = [1,2]\nOutput: 2\nExplanation:\nThe first distinct maximum is 2.\nThe second distinct maximum is 1.\nThe third distinct maximum does not exist, so the maximum (2) is returned instead.\n\nExample 3:\nInput: nums = [2,2,3,1]\nOutput: 1\nExplanation:\nThe first distinct maximum is 3.\nThe second distinct maximum is 2 (both 2's are counted together since they have the same value).\nThe third distinct maximum is 1.\n\nConstraints:\n- 1 <= nums.length <= 10^4\n- -2^31 <= nums[i] <= 2^31 - 1"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def thirdMax(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n count = 0\n top = [float(\"-inf\")] * 3\n for num in nums:\n if num > top[0]:\n top[0], top[1], top[2] = num, top[0], top[1]\n count += 1\n elif num != top[0] and num > top[1]:\n top[1], top[2] = num, top[1]\n count += 1\n elif num != top[0] and num != top[1] and num >= top[2]:\n top[2] = num\n count += 1\n\n if count < 3:\n return top[0]\n\n return top[2]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9924", "name": "LeetCode 0415: Add Strings"}{"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: Add Strings (Difficulty: Easy)\nTags: Math, String, Simulation\n\nGiven two non-negative integers, num1 and num2 represented as string, return the sum of num1 and num2 as a string.\nYou must solve the problem without using any built-in library for handling large integers (such as BigInteger). You must also not convert the inputs to integers directly.\n\nExample 1:\nInput: num1 = \"11\", num2 = \"123\"\nOutput: \"134\"\n\nExample 2:\nInput: num1 = \"456\", num2 = \"77\"\nOutput: \"533\"\n\nExample 3:\nInput: num1 = \"0\", num2 = \"0\"\nOutput: \"0\"\n\nConstraints:\n- 1 <= num1.length, num2.length <= 10^4\n- num1 and num2 consist of only digits.\n- num1 and num2 don't have any leading zeros except for the zero itself."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def addStrings(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"\n result = []\n i, j, carry = len(num1) - 1, len(num2) - 1, 0\n\n while i >= 0 or j >= 0 or carry:\n if i >= 0:\n carry += ord(num1[i]) - ord('0')\n i -= 1\n if j >= 0:\n carry += ord(num2[j]) - ord('0')\n j -= 1\n result.append(str(carry % 10))\n carry /= 10\n result.reverse()\n\n return \"\".join(result)\n\n def addStrings2(self, num1, num2):\n \"\"\"\n :type num1: str\n :type num2: str\n :rtype: str\n \"\"\"\n length = max(len(num1), len(num2))\n num1 = num1.zfill(length)[::-1]\n num2 = num2.zfill(length)[::-1]\n res, plus = '', 0\n for index, num in enumerate(num1):\n tmp = str(int(num) + int(num2[index]) + plus)\n res += tmp[-1]\n if int(tmp) > 9:\n plus = 1\n else:\n plus = 0\n if plus:\n res += '1'\n return res[::-1]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9925", "name": "LeetCode 0416: Partition Equal Subset Sum"}{"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: Partition Equal Subset Sum (Difficulty: Medium)\nTags: Array, Dynamic Programming\n\nGiven an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.\n\nExample 1:\nInput: nums = [1,5,11,5]\nOutput: true\nExplanation: The array can be partitioned as [1, 5, 5] and [11].\n\nExample 2:\nInput: nums = [1,2,3,5]\nOutput: false\nExplanation: The array cannot be partitioned into equal sum subsets.\n\nConstraints:\n- 1 <= nums.length <= 200\n- 1 <= nums[i] <= 100"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n * s), s is the sum of nums\n# Space: O(s)\n\nclass Solution(object):\n def canPartition(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n s = sum(nums)\n if s % 2:\n return False\n\n dp = [False] * (s/2 + 1)\n dp[0] = True\n for num in nums:\n for i in reversed(range(1, len(dp))):\n if num <= i:\n dp[i] = dp[i] or dp[i - num]\n return dp[-1]\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9926", "name": "LeetCode 0417: Pacific Atlantic Water Flow"}{"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: Pacific Atlantic Water Flow (Difficulty: Medium)\nTags: Array, Depth-First Search, Breadth-First Search, Matrix\n\nThere is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges.\nThe island is partitioned into a grid of square cells. You are given an m x n integer matrix heights where heights[r][c] represents the height above sea level of the cell at coordinate (r, c).\nThe island receives a lot of rain, and the rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell's height is less than or equal to the current cell's height. Water can flow from any cell adjacent to an ocean into the ocean.\nReturn a 2D list of grid coordinates result where result[i] = [ri, ci] denotes that rain water can flow from cell (ri, ci) to both the Pacific and Atlantic oceans.\n\nExample 1:\nInput: heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]]\nOutput: [[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]]\nExplanation: The following cells can flow to the Pacific and Atlantic oceans, as shown below:\n[0,4]: [0,4] -> Pacific Ocean \n [0,4] -> Atlantic Ocean\n[1,3]: [1,3] -> [0,3] -> Pacific Ocean \n [1,3] -> [1,4] -> Atlantic Ocean\n[1,4]: [1,4] -> [1,3] -> [0,3] -> Pacific Ocean \n [1,4] -> Atlantic Ocean\n[2,2]: [2,2] -> [1,2] -> [0,2] -> Pacific Ocean \n [2,2] -> [2,3] -> [2,4] -> Atlantic Ocean\n[3,0]: [3,0] -> Pacific Ocean \n [3,0] -> [4,0] -> Atlantic Ocean\n[3,1]: [3,1] -> [3,0] -> Pacific Ocean \n [3,1] -> [4,1] -> Atlantic Ocean\n[4,0]: [4,0] -> Pacific Ocean \n [4,0] -> Atlantic Ocean\nNote that there are other possible paths for these cells to flow to the Pacific and Atlantic oceans.\n\nExample 2:\nInput: heights = [[1]]\nOutput: [[0,0]]\nExplanation: The water can flow from the only cell to the Pacific and Atlantic oceans.\n\nConstraints:\n- m == heights.length\n- n == heights[r].length\n- 1 <= m, n <= 200\n- 0 <= heights[r][c] <= 10^5"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(m * n)\n# Space: O(m * n)\n\nclass Solution(object):\n def pacificAtlantic(self, matrix):\n \"\"\"\n :type matrix: List[List[int]]\n :rtype: List[List[int]]\n \"\"\"\n PACIFIC, ATLANTIC = 1, 2\n\n def pacificAtlanticHelper(matrix, x, y, prev_height, prev_val, visited, res):\n if (not 0 <= x < len(matrix)) or \\\n (not 0 <= y < len(matrix[0])) or \\\n matrix[x][y] < prev_height or \\\n (visited[x][y] | prev_val) == visited[x][y]:\n return\n\n visited[x][y] |= prev_val\n if visited[x][y] == (PACIFIC | ATLANTIC):\n res.append((x, y))\n\n for d in [(0, -1), (0, 1), (-1, 0), (1, 0)]:\n pacificAtlanticHelper(matrix, x + d[0], y + d[1], matrix[x][y], visited[x][y], visited, res)\n\n if not matrix:\n return []\n\n res = []\n m, n = len(matrix),len(matrix[0])\n visited = [[0 for _ in range(n)] for _ in range(m)]\n\n for i in range(m):\n pacificAtlanticHelper(matrix, i, 0, float(\"-inf\"), PACIFIC, visited, res)\n pacificAtlanticHelper(matrix, i, n - 1, float(\"-inf\"), ATLANTIC, visited, res)\n for j in range(n):\n pacificAtlanticHelper(matrix, 0, j, float(\"-inf\"), PACIFIC, visited, res)\n pacificAtlanticHelper(matrix, m - 1, j, float(\"-inf\"), ATLANTIC, visited, res)\n\n return res\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9928", "name": "LeetCode 0419: Battleships In A Board"}{"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: Battleships in a Board (Difficulty: Medium)\nTags: Array, Depth-First Search, Matrix\n\nGiven an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board.\nBattleships can only be placed horizontally or vertically on board. In other words, they can only be made of the shape 1 x k (1 row, k columns) or k x 1 (k rows, 1 column), where k can be of any size. At least one horizontal or vertical cell separates between two battleships (i.e., there are no adjacent battleships).\nFollow up: Could you do it in one-pass, using only O(1) extra memory and without modifying the values board?\n\nExample 1:\nInput: board = [[\"X\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"]]\nOutput: 2\n\nExample 2:\nInput: board = [[\".\"]]\nOutput: 0\n\nConstraints:\n- m == board.length\n- n == board[i].length\n- 1 <= m, n <= 200\n- board[i][j] is either '.' or 'X'."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(m * n)\n# Space: O(1)\n\n\nclass Solution(object):\n def countBattleships(self, board):\n \"\"\"\n :type board: List[List[str]]\n :rtype: int\n \"\"\"\n if not board or not board[0]:\n return 0\n\n cnt = 0\n for i in range(len(board)):\n for j in range(len(board[0])):\n cnt += int(board[i][j] == 'X' and\n (i == 0 or board[i - 1][j] != 'X') and\n (j == 0 or board[i][j - 1] != 'X'))\n return cnt\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9929", "name": "LeetCode 0420: Strong Password Checker"}{"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: Strong Password Checker (Difficulty: Hard)\nTags: String, Greedy, Heap (Priority Queue)\n\nA password is considered strong if the below conditions are all met:\nGiven a string password, return the minimum number of steps required to make password strong. if password is already strong, return 0.\nIn one step, you can:\n\nExample 1:\nInput: password = \"a\"\nOutput: 5\n\nExample 2:\nInput: password = \"aA1\"\nOutput: 3\n\nExample 3:\nInput: password = \"1337C0d3\"\nOutput: 0\n\nConstraints:\n- 1 <= password.length <= 50\n- password consists of letters, digits, dot '.' or exclamation mark '!'."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nclass Solution(object):\n def strongPasswordChecker(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n missing_type_cnt = 3\n if any('a' <= c <= 'z' for c in s):\n missing_type_cnt -= 1\n if any('A' <= c <= 'Z' for c in s):\n missing_type_cnt -= 1\n if any(c.isdigit() for c in s):\n missing_type_cnt -= 1\n\n total_change_cnt = 0\n one_change_cnt, two_change_cnt, three_change_cnt = 0, 0, 0\n i = 2\n while i < len(s):\n if s[i] == s[i-1] == s[i-2]:\n length = 2\n while i < len(s) and s[i] == s[i-1]:\n length += 1\n i += 1\n\n total_change_cnt += length / 3\n if length % 3 == 0:\n one_change_cnt += 1\n elif length % 3 == 1:\n two_change_cnt += 1\n else:\n three_change_cnt += 1\n else:\n i += 1\n\n if len(s) < 6:\n return max(missing_type_cnt, 6 - len(s))\n elif len(s) <= 20:\n return max(missing_type_cnt, total_change_cnt)\n else:\n delete_cnt = len(s) - 20\n\n total_change_cnt -= min(delete_cnt, one_change_cnt * 1) / 1\n total_change_cnt -= min(max(delete_cnt - one_change_cnt, 0), two_change_cnt * 2) / 2\n total_change_cnt -= min(max(delete_cnt - one_change_cnt - 2 * two_change_cnt, 0), three_change_cnt * 3) / 3\n\n return delete_cnt + max(missing_type_cnt, total_change_cnt)\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9930", "name": "LeetCode 0421: Maximum Xor Of Two Numbers In An Array"}{"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: Maximum XOR of Two Numbers in an Array (Difficulty: Medium)\nTags: Array, Hash Table, Bit Manipulation, Trie\n\nGiven an integer array nums, return the maximum result of nums[i] XOR nums[j], where 0 <= i <= j < n.\n\nExample 1:\nInput: nums = [3,10,5,25,2,8]\nOutput: 28\nExplanation: The maximum result is 5 XOR 25 = 28.\n\nExample 2:\nInput: nums = [14,70,53,83,49,91,36,80,92,51,66,70]\nOutput: 127\n\nConstraints:\n- 1 <= nums.length <= 2 * 10^5\n- 0 <= nums[i] <= 2^31 - 1"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(nlogr), r = max(nums)\n# Space: O(t)\n\nclass Solution(object):\n def findMaximumXOR(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n class Trie(object):\n def __init__(self, bit_length):\n self.__nodes = []\n self.__new_node()\n self.__bit_length = bit_length\n \n def __new_node(self):\n self.__nodes.append([-1]*2)\n return len(self.__nodes)-1\n\n def insert(self, num):\n curr = 0\n for i in reversed(range(self.__bit_length)):\n x = num>>i\n if self.__nodes[curr][x&1] == -1:\n self.__nodes[curr][x&1] = self.__new_node()\n curr = self.__nodes[curr][x&1]\n \n def query(self, num):\n result = curr = 0\n for i in reversed(range(self.__bit_length)):\n result <<= 1\n x = num>>i\n if self.__nodes[curr][1^(x&1)] != -1:\n curr = self.__nodes[curr][1^(x&1)]\n result |= 1\n else:\n curr = self.__nodes[curr][x&1]\n return result\n\n trie = Trie(max(nums).bit_length())\n result = 0\n for num in nums:\n trie.insert(num)\n result = max(result, trie.query(num))\n return result\n\n\n# Time: O(nlogr), r = max(nums)\n# Space: O(n)\nclass Solution2(object):\n def findMaximumXOR(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: int\n \"\"\"\n result = 0\n for i in reversed(range(max(nums).bit_length())):\n result <<= 1\n prefixes = set()\n for n in nums:\n prefixes.add(n >> i)\n for p in prefixes:\n if (result | 1) ^ p in prefixes:\n result |= 1\n break\n return result\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9932", "name": "LeetCode 0423: Reconstruct Original Digits From English"}{"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: Reconstruct Original Digits from English (Difficulty: Medium)\nTags: Hash Table, Math, String\n\nGiven a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.\n\nExample 1:\nInput: s = \"owoztneoer\"\nOutput: \"012\"\n\nExample 2:\nInput: s = \"fviefuro\"\nOutput: \"45\"\n\nConstraints:\n- 1 <= s.length <= 10^5\n- s[i] is one of the characters [\"e\",\"g\",\"f\",\"i\",\"h\",\"o\",\"n\",\"s\",\"r\",\"u\",\"t\",\"w\",\"v\",\"x\",\"z\"].\n- s is guaranteed to be valid."}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nfrom collections import Counter\n\nclass Solution(object):\n def originalDigits(self, s):\n \"\"\"\n :type s: str\n :rtype: str\n \"\"\"\n # The count of each char in each number string.\n cnts = [Counter(_) for _ in [\"zero\", \"one\", \"two\", \"three\", \\\n \"four\", \"five\", \"six\", \"seven\", \\\n \"eight\", \"nine\"]]\n\n # The order for greedy method.\n order = [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]\n\n # The unique char in the order.\n unique_chars = ['z', 'o', 'w', 't', 'u', \\\n 'f', 'x', 's', 'g', 'n']\n\n cnt = Counter(list(s))\n res = []\n for i in order:\n while cnt[unique_chars[i]] > 0:\n cnt -= cnts[i]\n res.append(i)\n res.sort()\n\n return \"\".join(map(str, res))\n\n"}}1234{"type": "session", "harness": "opencode", "id": "cp-9933", "name": "LeetCode 0424: Longest Repeating Character Replacement"}{"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: Longest Repeating Character Replacement (Difficulty: Medium)\nTags: Hash Table, String, Sliding Window\n\nYou are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times.\nReturn the length of the longest substring containing the same letter you can get after performing the above operations.\n\nExample 1:\nInput: s = \"ABAB\", k = 2\nOutput: 4\nExplanation: Replace the two 'A's with two 'B's or vice versa.\n\nExample 2:\nInput: s = \"AABABBA\", k = 1\nOutput: 4\nExplanation: Replace the one 'A' in the middle with 'B' and form \"AABBBBA\".\nThe substring \"BBBB\" has the longest repeating letters, which is 4.\nThere may exists other ways to achieve this answer too.\n\nConstraints:\n- 1 <= s.length <= 10^5\n- s consists of only uppercase English letters.\n- 0 <= k <= s.length"}}{"type": "message", "message": {"role": "assistant", "content": "# Time: O(n)\n# Space: O(1)\n\nimport collections\n\n\nclass Solution(object):\n def characterReplacement(self, s, k):\n \"\"\"\n :type s: str\n :type k: int\n :rtype: int\n \"\"\"\n result, max_count = 0, 0\n count = collections.Counter()\n for i in range(len(s)):\n count[s[i]] += 1\n max_count = max(max_count, count[s[i]])\n if result - max_count >= k:\n count[s[i-result]] -= 1\n else:\n result += 1\n return result\n\n"}}cp/cp-9877.jsonlAdded+4
cp/cp-9880.jsonlAdded+4
cp/cp-9881.jsonlAdded+4
cp/cp-9882.jsonlAdded+4
cp/cp-9883.jsonlAdded+4
cp/cp-9884.jsonlAdded+4
cp/cp-9885.jsonlAdded+4
cp/cp-9886.jsonlAdded+4
cp/cp-9887.jsonlAdded+4
cp/cp-9889.jsonlAdded+4
cp/cp-9890.jsonlAdded+4
cp/cp-9891.jsonlAdded+4
cp/cp-9892.jsonlAdded+4
cp/cp-9893.jsonlAdded+4
cp/cp-9894.jsonlAdded+4
cp/cp-9895.jsonlAdded+4
cp/cp-9896.jsonlAdded+4
cp/cp-9897.jsonlAdded+4
cp/cp-9898.jsonlAdded+4
cp/cp-9899.jsonlAdded+4
cp/cp-9900.jsonlAdded+4
cp/cp-9901.jsonlAdded+4
cp/cp-9902.jsonlAdded+4
cp/cp-9903.jsonlAdded+4
cp/cp-9904.jsonlAdded+4
cp/cp-9905.jsonlAdded+4
cp/cp-9906.jsonlAdded+4
cp/cp-9907.jsonlAdded+4
cp/cp-9908.jsonlAdded+4
cp/cp-9909.jsonlAdded+4
cp/cp-9910.jsonlAdded+4
cp/cp-9911.jsonlAdded+4
cp/cp-9912.jsonlAdded+4
cp/cp-9913.jsonlAdded+4
cp/cp-9914.jsonlAdded+4
cp/cp-9915.jsonlAdded+4
cp/cp-9916.jsonlAdded+4
cp/cp-9918.jsonlAdded+4
cp/cp-9919.jsonlAdded+4
cp/cp-9921.jsonlAdded+4
cp/cp-9922.jsonlAdded+4
cp/cp-9923.jsonlAdded+4
cp/cp-9924.jsonlAdded+4
cp/cp-9925.jsonlAdded+4
cp/cp-9926.jsonlAdded+4
cp/cp-9928.jsonlAdded+4
cp/cp-9929.jsonlAdded+4
cp/cp-9930.jsonlAdded+4
cp/cp-9932.jsonlAdded+4
cp/cp-9933.jsonlAdded+4