smshahbaj commited on
Commit
7e9b03f
·
verified ·
1 Parent(s): 7a3104c

Upload train.jsonl with huggingface_hub

Browse files
Files changed (1) hide show
  1. train.jsonl +25 -0
train.jsonl ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {"id":"vcr_2ab4ebab9ecd","difficulty":"medium","category":"binary_search","problem":"Versions 1..n. All versions >= bad are bad. Find the first bad version. Parameter bad is provided for testing.","signature":"def first_bad_version(n: int, bad: int) -> int:","reasoning":"Lower-bound binary search on the is_bad predicate.","code":"def first_bad_version(n: int, bad: int) -> int:\n def is_bad(v):\n return v >= bad\n lo, hi = 1, n\n while lo < hi:\n mid = (lo + hi) // 2\n if is_bad(mid):\n hi = mid\n else:\n lo = mid + 1\n return lo\n","tests":[{"input":{"n":12,"bad":1},"output":1},{"input":{"n":20,"bad":8},"output":8},{"input":{"n":17,"bad":5},"output":5}],"verified":true,"language":"python","code_hash":"73591920a83cf64d","sft_text":"### Problem\nVersions 1..n. All versions >= bad are bad. Find the first bad version. Parameter bad is provided for testing.\n\n### Reasoning\nLower-bound binary search on the is_bad predicate.\n\n### Solution\n```python\ndef first_bad_version(n: int, bad: int) -> int:\n def is_bad(v):\n return v >= bad\n lo, hi = 1, n\n while lo < hi:\n mid = (lo + hi) // 2\n if is_bad(mid):\n hi = mid\n else:\n lo = mid + 1\n return lo\n```","meta":{"v":"ok"}}
2
+ {"id":"vcr_ea518b929dcd","difficulty":"easy","category":"matrix","problem":"Sum primary and secondary diagonals of a square matrix (center counted once if n is odd).","signature":"def diagonal_sum(mat: list[list[int]]) -> int:","reasoning":"Add both diagonals. Skip the center cell the second time when n is odd.","code":"def diagonal_sum(mat: list[list[int]]) -> int:\n n = len(mat)\n s = 0\n for i in range(n):\n s += mat[i][i]\n if i != n - 1 - i:\n s += mat[i][n - 1 - i]\n return s\n","tests":[{"input":{"mat":[[8,-7],[9,4]]},"output":14},{"input":{"mat":[[-5,-4],[-2,-2]]},"output":-13},{"input":{"mat":[[3,-2],[5,3]]},"output":9}],"verified":true,"language":"python","code_hash":"ab7287cd5b745011","sft_text":"### Problem\nSum primary and secondary diagonals of a square matrix (center counted once if n is odd).\n\n### Reasoning\nAdd both diagonals. Skip the center cell the second time when n is odd.\n\n### Solution\n```python\ndef diagonal_sum(mat: list[list[int]]) -> int:\n n = len(mat)\n s = 0\n for i in range(n):\n s += mat[i][i]\n if i != n - 1 - i:\n s += mat[i][n - 1 - i]\n return s\n```","meta":{"v":"ok"}}
3
+ {"id":"vcr_1a8a0f0c2ea0","difficulty":"easy","category":"math","problem":"Return FizzBuzz results from 1 to n inclusive.","signature":"def fizzbuzz(n: int) -> list[str]:","reasoning":"Test divisibility by 15 before 3 or 5 so common multiples are labeled correctly.","code":"def fizzbuzz(n: int) -> list[str]:\n out = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n out.append('FizzBuzz')\n elif i % 3 == 0:\n out.append('Fizz')\n elif i % 5 == 0:\n out.append('Buzz')\n else:\n out.append(str(i))\n return out\n","tests":[{"input":{"n":22},"output":["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz","16","17","Fizz","19","Buzz","Fizz","22"]},{"input":{"n":5},"output":["1","2","Fizz","4","Buzz"]},{"input":{"n":16},"output":["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz","16"]},{"input":{"n":34},"output":["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz","16","17","Fizz","19","Buzz","Fizz","22","23","Fizz","Buzz","26","Fizz","28","29","FizzBuzz","31","32","Fizz","34"]}],"verified":true,"language":"python","code_hash":"2da7b8aadef1ab6e","sft_text":"### Problem\nReturn FizzBuzz results from 1 to n inclusive.\n\n### Reasoning\nTest divisibility by 15 before 3 or 5 so common multiples are labeled correctly.\n\n### Solution\n```python\ndef fizzbuzz(n: int) -> list[str]:\n out = []\n for i in range(1, n + 1):\n if i % 15 == 0:\n out.append('FizzBuzz')\n elif i % 3 == 0:\n out.append('Fizz')\n elif i % 5 == 0:\n out.append('Buzz')\n else:\n out.append(str(i))\n return out\n```","meta":{"v":"ok"}}
4
+ {"id":"vcr_a57cd5c304e5","difficulty":"medium","category":"greedy","problem":"From index 0 you may jump at most nums[i] steps. Return True if the last index is reachable.","signature":"def can_jump(nums: list[int]) -> bool:","reasoning":"Track the farthest reachable index. If the current index exceeds it, fail.","code":"def can_jump(nums: list[int]) -> bool:\n reach = 0\n for i, x in enumerate(nums):\n if i > reach:\n return False\n reach = max(reach, i + x)\n if reach >= len(nums) - 1:\n return True\n return reach >= len(nums) - 1\n","tests":[{"input":{"nums":[0,1,3,2,2,1,0]},"output":false},{"input":{"nums":[2,0,0,3,0,2,2,2,0]},"output":false},{"input":{"nums":[3,0,3,0,2,2,1,0]},"output":true}],"verified":true,"language":"python","code_hash":"b6a822bf8a6dd0fa","sft_text":"### Problem\nFrom index 0 you may jump at most nums[i] steps. Return True if the last index is reachable.\n\n### Reasoning\nTrack the farthest reachable index. If the current index exceeds it, fail.\n\n### Solution\n```python\ndef can_jump(nums: list[int]) -> bool:\n reach = 0\n for i, x in enumerate(nums):\n if i > reach:\n return False\n reach = max(reach, i + x)\n if reach >= len(nums) - 1:\n return True\n return reach >= len(nums) - 1\n```","meta":{"v":"ok"}}
5
+ {"id":"vcr_2e4df53df004","difficulty":"easy","category":"hashmap","problem":"Return True if any value appears at least twice in nums.","signature":"def contains_duplicate(nums: list[int]) -> bool:","reasoning":"Duplicates exist if and only if len(list) > len(set). O(n).","code":"def contains_duplicate(nums: list[int]) -> bool:\n return len(nums) != len(set(nums))\n","tests":[{"input":{"nums":[74,20,59,25,97,71,116,162,93,41,94,90,53,171,68]},"output":false},{"input":{"nums":[19,20,5,17]},"output":false},{"input":{"nums":[5,14,12,8,20,22]},"output":false}],"verified":true,"language":"python","code_hash":"f35d656879667375","sft_text":"### Problem\nReturn True if any value appears at least twice in nums.\n\n### Reasoning\nDuplicates exist if and only if len(list) > len(set). O(n).\n\n### Solution\n```python\ndef contains_duplicate(nums: list[int]) -> bool:\n return len(nums) != len(set(nums))\n```","meta":{"v":"ok"}}
6
+ {"id":"vcr_c76572145f10","difficulty":"easy","category":"greedy","problem":"Daily stock prices. Max profit from one buy and one later sell (0 if impossible).","signature":"def max_profit(prices: list[int]) -> int:","reasoning":"Track the minimum price so far. Maximize price minus that minimum.","code":"def max_profit(prices: list[int]) -> int:\n best, lo = 0, prices[0]\n for x in prices[1:]:\n best = max(best, x - lo)\n lo = min(lo, x)\n return best\n","tests":[{"input":{"prices":[44,21,54,50,50,4,15]},"output":33},{"input":{"prices":[21,26,18]},"output":5},{"input":{"prices":[14,37,21,14]},"output":23}],"verified":true,"language":"python","code_hash":"b40e7d74850552a7","sft_text":"### Problem\nDaily stock prices. Max profit from one buy and one later sell (0 if impossible).\n\n### Reasoning\nTrack the minimum price so far. Maximize price minus that minimum.\n\n### Solution\n```python\ndef max_profit(prices: list[int]) -> int:\n best, lo = 0, prices[0]\n for x in prices[1:]:\n best = max(best, x - lo)\n lo = min(lo, x)\n return best\n```","meta":{"v":"ok"}}
7
+ {"id":"vcr_cd6d70257d91","difficulty":"medium","category":"two_pointers","problem":"Return True if lowercase string s is a palindrome.","signature":"def is_palindrome(s: str) -> bool:","reasoning":"Two pointers from both ends. Any mismatch means False. O(n) time, O(1) space.","code":"def is_palindrome(s: str) -> bool:\n i, j = 0, len(s) - 1\n while i < j:\n if s[i] != s[j]:\n return False\n i += 1\n j -= 1\n return True\n","tests":[{"input":{"s":"cddcbbdaaabbda"},"output":false},{"input":{"s":"bcbcbcac"},"output":false},{"input":{"s":"ccb"},"output":false}],"verified":true,"language":"python","code_hash":"9742b2c402b3548d","sft_text":"### Problem\nReturn True if lowercase string s is a palindrome.\n\n### Reasoning\nTwo pointers from both ends. Any mismatch means False. O(n) time, O(1) space.\n\n### Solution\n```python\ndef is_palindrome(s: str) -> bool:\n i, j = 0, len(s) - 1\n while i < j:\n if s[i] != s[j]:\n return False\n i += 1\n j -= 1\n return True\n```","meta":{"v":"ok"}}
8
+ {"id":"vcr_5015e2198b6d","difficulty":"medium","category":"stack","problem":"Return True if a string of '(' and ')' is balanced.","signature":"def valid_parentheses(s: str) -> bool:","reasoning":"Maintain a running balance. Never go negative; must end at zero.","code":"def valid_parentheses(s: str) -> bool:\n bal = 0\n for ch in s:\n bal += 1 if ch == '(' else -1\n if bal < 0:\n return False\n return bal == 0\n","tests":[{"input":{"s":"((()))"},"output":true},{"input":{"s":"()"},"output":true},{"input":{"s":"(()(()"},"output":false}],"verified":true,"language":"python","code_hash":"5d0846a128e0bec5","sft_text":"### Problem\nReturn True if a string of '(' and ')' is balanced.\n\n### Reasoning\nMaintain a running balance. Never go negative; must end at zero.\n\n### Solution\n```python\ndef valid_parentheses(s: str) -> bool:\n bal = 0\n for ch in s:\n bal += 1 if ch == '(' else -1\n if bal < 0:\n return False\n return bal == 0\n```","meta":{"v":"ok"}}
9
+ {"id":"vcr_7ed2df9cbc7b","difficulty":"medium","category":"array","problem":"Maximum sum of any non-empty contiguous subarray (Kadane, O(n)).","signature":"def max_subarray(nums: list[int]) -> int:","reasoning":"At each step cur = max(x, cur+x). Track global best. Handles all-negative arrays.","code":"def max_subarray(nums: list[int]) -> int:\n best = cur = nums[0]\n for x in nums[1:]:\n cur = max(x, cur + x)\n best = max(best, cur)\n return best\n","tests":[{"input":{"nums":[12,17,-8,-2,15,20,9,-5,16,-6,1,7,5,10,15]},"output":106},{"input":{"nums":[-9,-5,-5,-10,-2,-12,6,5,-5,6]},"output":12},{"input":{"nums":[-12,-10,10,8,-11,-5]},"output":18}],"verified":true,"language":"python","code_hash":"ec0ac96e944ed958","sft_text":"### Problem\nMaximum sum of any non-empty contiguous subarray (Kadane, O(n)).\n\n### Reasoning\nAt each step cur = max(x, cur+x). Track global best. Handles all-negative arrays.\n\n### Solution\n```python\ndef max_subarray(nums: list[int]) -> int:\n best = cur = nums[0]\n for x in nums[1:]:\n cur = max(x, cur + x)\n best = max(best, cur)\n return best\n```","meta":{"v":"ok"}}
10
+ {"id":"vcr_b36fe2107d43","difficulty":"medium","category":"hashmap","problem":"Group anagrams by sorted character signature. Return sorted group sizes.","signature":"def anagram_group_sizes(strs: list[str]) -> list[int]:","reasoning":"Signature is sorted characters. Bucket words, then emit sorted sizes.","code":"def anagram_group_sizes(strs: list[str]) -> list[int]:\n from collections import defaultdict\n g = defaultdict(list)\n for w in strs:\n g[''.join(sorted(w))].append(w)\n return sorted(len(v) for v in g.values())\n","tests":[{"input":{"strs":["aac","ca","bb","ac"]},"output":[1,1,2]},{"input":{"strs":["bbb","aaa","bba","aaa","bab"]},"output":[1,2,2]},{"input":{"strs":["bba","aba","aaa","aab"]},"output":[1,1,2]}],"verified":true,"language":"python","code_hash":"98cc167af301acd0","sft_text":"### Problem\nGroup anagrams by sorted character signature. Return sorted group sizes.\n\n### Reasoning\nSignature is sorted characters. Bucket words, then emit sorted sizes.\n\n### Solution\n```python\ndef anagram_group_sizes(strs: list[str]) -> list[int]:\n from collections import defaultdict\n g = defaultdict(list)\n for w in strs:\n g[''.join(sorted(w))].append(w)\n return sorted(len(v) for v in g.values())\n```","meta":{"v":"ok"}}
11
+ {"id":"vcr_2b2d2449f4a3","difficulty":"medium","category":"dp","problem":"You may climb 1 or 2 steps. How many distinct ways to reach step n?","signature":"def climb_stairs(n: int) -> int:","reasoning":"Recurrence f(n) = f(n-1) + f(n-2). Compute iteratively like Fibonacci.","code":"def climb_stairs(n: int) -> int:\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b\n","tests":[{"input":{"n":17},"output":2584},{"input":{"n":2},"output":2},{"input":{"n":5},"output":8},{"input":{"n":9},"output":55}],"verified":true,"language":"python","code_hash":"44b3efbdd775ca2a","sft_text":"### Problem\nYou may climb 1 or 2 steps. How many distinct ways to reach step n?\n\n### Reasoning\nRecurrence f(n) = f(n-1) + f(n-2). Compute iteratively like Fibonacci.\n\n### Solution\n```python\ndef climb_stairs(n: int) -> int:\n if n <= 2:\n return n\n a, b = 1, 2\n for _ in range(3, n + 1):\n a, b = b, a + b\n return b\n```","meta":{"v":"ok"}}
12
+ {"id":"vcr_9b0581e8c371","difficulty":"easy","category":"string","problem":"Count contiguous groups of identical characters (example: aabbc -> 3).","signature":"def count_char_groups(s: str) -> int:","reasoning":"Walk the string and increment whenever the character changes.","code":"def count_char_groups(s: str) -> int:\n if not s:\n return 0\n groups = 1\n for i in range(1, len(s)):\n if s[i] != s[i - 1]:\n groups += 1\n return groups\n","tests":[{"input":{"s":"abab"},"output":4},{"input":{"s":"bbbcccc"},"output":2},{"input":{"s":"aabaacccac"},"output":6}],"verified":true,"language":"python","code_hash":"b9d6cf6fe0c38dc7","sft_text":"### Problem\nCount contiguous groups of identical characters (example: aabbc -> 3).\n\n### Reasoning\nWalk the string and increment whenever the character changes.\n\n### Solution\n```python\ndef count_char_groups(s: str) -> int:\n if not s:\n return 0\n groups = 1\n for i in range(1, len(s)):\n if s[i] != s[i - 1]:\n groups += 1\n return groups\n```","meta":{"v":"ok"}}
13
+ {"id":"vcr_616fa207f208","difficulty":"easy","category":"two_pointers","problem":"Sorted nums may contain duplicates. Return unique values in order as a new list.","signature":"def remove_duplicates_sorted(nums: list[int]) -> list[int]:","reasoning":"Scan left to right. Append only when the value differs from the last kept value.","code":"def remove_duplicates_sorted(nums: list[int]) -> list[int]:\n if not nums:\n return []\n out = [nums[0]]\n for x in nums[1:]:\n if x != out[-1]:\n out.append(x)\n return out\n","tests":[{"input":{"nums":[0,1,1,2,4,6,6,8,8,8,10,10,13,15]},"output":[0,1,2,4,6,8,10,13,15]},{"input":{"nums":[2,6,7,8,8,11,11]},"output":[2,6,7,8,11]},{"input":{"nums":[1,1,11]},"output":[1,11]}],"verified":true,"language":"python","code_hash":"9a3cff9b9f3d1889","sft_text":"### Problem\nSorted nums may contain duplicates. Return unique values in order as a new list.\n\n### Reasoning\nScan left to right. Append only when the value differs from the last kept value.\n\n### Solution\n```python\ndef remove_duplicates_sorted(nums: list[int]) -> list[int]:\n if not nums:\n return []\n out = [nums[0]]\n for x in nums[1:]:\n if x != out[-1]:\n out.append(x)\n return out\n```","meta":{"v":"ok"}}
14
+ {"id":"vcr_8f76027f2675","difficulty":"easy","category":"bit","problem":"Return the number of set bits in non-negative integer n (Hamming weight).","signature":"def hamming_weight(n: int) -> int:","reasoning":"Count the least bit with n & 1, then shift right until n is 0.","code":"def hamming_weight(n: int) -> int:\n c = 0\n while n:\n c += n & 1\n n >>= 1\n return c\n","tests":[{"input":{"n":40687},"output":12},{"input":{"n":7361},"output":6},{"input":{"n":6525},"output":9}],"verified":true,"language":"python","code_hash":"24a3439f03888452","sft_text":"### Problem\nReturn the number of set bits in non-negative integer n (Hamming weight).\n\n### Reasoning\nCount the least bit with n & 1, then shift right until n is 0.\n\n### Solution\n```python\ndef hamming_weight(n: int) -> int:\n c = 0\n while n:\n c += n & 1\n n >>= 1\n return c\n```","meta":{"v":"ok"}}
15
+ {"id":"vcr_dc70b75b7f3f","difficulty":"easy","category":"array","problem":"Return running sum where out[i] = nums[0] + ... + nums[i].","signature":"def running_sum(nums: list[int]) -> list[int]:","reasoning":"Accumulate once left to right. O(n).","code":"def running_sum(nums: list[int]) -> list[int]:\n acc, out = 0, []\n for x in nums:\n acc += x\n out.append(acc)\n return out\n","tests":[{"input":{"nums":[-11,-14,26,19,8,4,-22,10,-10]},"output":[-11,-25,1,20,28,32,10,20,10]},{"input":{"nums":[2,-8,13]},"output":[2,-6,7]},{"input":{"nums":[9,4,5,7,-2,18,12,16,2]},"output":[9,13,18,25,23,41,53,69,71]}],"verified":true,"language":"python","code_hash":"9222adfde6ffe86d","sft_text":"### Problem\nReturn running sum where out[i] = nums[0] + ... + nums[i].\n\n### Reasoning\nAccumulate once left to right. O(n).\n\n### Solution\n```python\ndef running_sum(nums: list[int]) -> list[int]:\n acc, out = 0, []\n for x in nums:\n acc += x\n out.append(acc)\n return out\n```","meta":{"v":"ok"}}
16
+ {"id":"vcr_8d232644c8ec","difficulty":"medium","category":"binary_search","problem":"Sorted distinct nums. Return index of target, or the insertion index if missing.","signature":"def search_insert(nums: list[int], target: int) -> int:","reasoning":"Binary search for the lower bound of target.","code":"def search_insert(nums: list[int], target: int) -> int:\n lo, hi = 0, len(nums)\n while lo < hi:\n mid = (lo + hi) // 2\n if nums[mid] < target:\n lo = mid + 1\n else:\n hi = mid\n return lo\n","tests":[{"input":{"nums":[10,15,16,17,27,28,30,31,33,35,40,47],"target":40},"output":10},{"input":{"nums":[4,15,17,18,28,39],"target":21},"output":4},{"input":{"nums":[5,8,9,13,14,24,34,36],"target":4},"output":0}],"verified":true,"language":"python","code_hash":"97339c7a2a724cba","sft_text":"### Problem\nSorted distinct nums. Return index of target, or the insertion index if missing.\n\n### Reasoning\nBinary search for the lower bound of target.\n\n### Solution\n```python\ndef search_insert(nums: list[int], target: int) -> int:\n lo, hi = 0, len(nums)\n while lo < hi:\n mid = (lo + hi) // 2\n if nums[mid] < target:\n lo = mid + 1\n else:\n hi = mid\n return lo\n```","meta":{"v":"ok"}}
17
+ {"id":"vcr_a01afaf3dccb","difficulty":"medium","category":"array","problem":"out[i] is product of all elements except nums[i]. O(n) without division.","signature":"def product_except_self(nums: list[int]) -> list[int]:","reasoning":"Build prefix products, then multiply by suffix products in a reverse pass.","code":"def product_except_self(nums: list[int]) -> list[int]:\n n = len(nums)\n out = [1] * n\n left = 1\n for i in range(n):\n out[i] = left\n left *= nums[i]\n right = 1\n for i in range(n - 1, -1, -1):\n out[i] *= right\n right *= nums[i]\n return out\n","tests":[{"input":{"nums":[0,6,5,2,3]},"output":[180,0,0,0,0]},{"input":{"nums":[3,2,4,1,1,5,3]},"output":[120,180,90,360,360,72,120]},{"input":{"nums":[4,4,3,2,1,3]},"output":[72,72,96,144,288,96]}],"verified":true,"language":"python","code_hash":"e6962ae39100e8b1","sft_text":"### Problem\nout[i] is product of all elements except nums[i]. O(n) without division.\n\n### Reasoning\nBuild prefix products, then multiply by suffix products in a reverse pass.\n\n### Solution\n```python\ndef product_except_self(nums: list[int]) -> list[int]:\n n = len(nums)\n out = [1] * n\n left = 1\n for i in range(n):\n out[i] = left\n left *= nums[i]\n right = 1\n for i in range(n - 1, -1, -1):\n out[i] *= right\n right *= nums[i]\n return out\n```","meta":{"v":"ok"}}
18
+ {"id":"vcr_afc5f5faeca5","difficulty":"medium","category":"two_pointers","problem":"Sorted nums: find indices i < j with nums[i] + nums[j] = target using O(n) two pointers.","signature":"def two_sum_sorted(nums: list[int], target: int) -> list[int]:","reasoning":"Start at both ends. Move the pointer that brings the sum closer to target.","code":"def two_sum_sorted(nums: list[int], target: int) -> list[int]:\n i, j = 0, len(nums) - 1\n while i < j:\n s = nums[i] + nums[j]\n if s == target:\n return [i, j]\n if s < target:\n i += 1\n else:\n j -= 1\n return []\n","tests":[{"input":{"nums":[6,8,32,44,45],"target":52},"output":[1,3]},{"input":{"nums":[-8,-5,0,1,2,4,9,14,15,24,28],"target":33},"output":[6,9]},{"input":{"nums":[-18,0,6,10,27,29,34],"target":39},"output":[3,5]}],"verified":true,"language":"python","code_hash":"0fdf37b1be7420d0","sft_text":"### Problem\nSorted nums: find indices i < j with nums[i] + nums[j] = target using O(n) two pointers.\n\n### Reasoning\nStart at both ends. Move the pointer that brings the sum closer to target.\n\n### Solution\n```python\ndef two_sum_sorted(nums: list[int], target: int) -> list[int]:\n i, j = 0, len(nums) - 1\n while i < j:\n s = nums[i] + nums[j]\n if s == target:\n return [i, j]\n if s < target:\n i += 1\n else:\n j -= 1\n return []\n```","meta":{"v":"ok"}}
19
+ {"id":"vcr_a46d323928d4","difficulty":"easy","category":"matrix","problem":"Return the sum of all elements in a 2D matrix.","signature":"def matrix_sum(mat: list[list[int]]) -> int:","reasoning":"Sum each row, then sum those totals.","code":"def matrix_sum(mat: list[list[int]]) -> int:\n return sum(sum(row) for row in mat)\n","tests":[{"input":{"mat":[[0,4],[7,0],[9,5]]},"output":25},{"input":{"mat":[[1,4],[5,6],[2,3],[2,5]]},"output":28},{"input":{"mat":[[4,2,4,7],[4,5,1,7],[1,2,3,6],[5,1,6,0]]},"output":58}],"verified":true,"language":"python","code_hash":"1b4635892b4bdc45","sft_text":"### Problem\nReturn the sum of all elements in a 2D matrix.\n\n### Reasoning\nSum each row, then sum those totals.\n\n### Solution\n```python\ndef matrix_sum(mat: list[list[int]]) -> int:\n return sum(sum(row) for row in mat)\n```","meta":{"v":"ok"}}
20
+ {"id":"vcr_8328cbb0b8b0","difficulty":"medium","category":"dp","problem":"Houses in a line with values nums. Cannot rob adjacent houses. Maximum amount.","signature":"def rob(nums: list[int]) -> int:","reasoning":"DP: for each house choose max(skip, take + prev2). O(n) time, O(1) space.","code":"def rob(nums: list[int]) -> int:\n prev2 = prev1 = 0\n for x in nums:\n prev2, prev1 = prev1, max(prev1, prev2 + x)\n return prev1\n","tests":[{"input":{"nums":[30,19,1,23,25,29]},"output":82},{"input":{"nums":[9,14,20,0,1,15,12,13,3,15]},"output":72},{"input":{"nums":[2,2,10,19,4,2,4,8,19]},"output":44}],"verified":true,"language":"python","code_hash":"adc43e90c6cebcb1","sft_text":"### Problem\nHouses in a line with values nums. Cannot rob adjacent houses. Maximum amount.\n\n### Reasoning\nDP: for each house choose max(skip, take + prev2). O(n) time, O(1) space.\n\n### Solution\n```python\ndef rob(nums: list[int]) -> int:\n prev2 = prev1 = 0\n for x in nums:\n prev2, prev1 = prev1, max(prev1, prev2 + x)\n return prev1\n```","meta":{"v":"ok"}}
21
+ {"id":"vcr_c60967dfb4b4","difficulty":"easy","category":"math","problem":"Return the greatest common divisor of positive integers a and b.","signature":"def gcd(a: int, b: int) -> int:","reasoning":"Euclidean algorithm: replace (a, b) with (b, a % b) until b is 0.","code":"def gcd(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n","tests":[{"input":{"a":130,"b":155},"output":5},{"input":{"a":111,"b":26},"output":1},{"input":{"a":180,"b":30},"output":30}],"verified":true,"language":"python","code_hash":"0a8801b251631b1d","sft_text":"### Problem\nReturn the greatest common divisor of positive integers a and b.\n\n### Reasoning\nEuclidean algorithm: replace (a, b) with (b, a % b) until b is 0.\n\n### Solution\n```python\ndef gcd(a: int, b: int) -> int:\n while b:\n a, b = b, a % b\n return a\n```","meta":{"v":"ok"}}
22
+ {"id":"vcr_f7cb48bdb8bc","difficulty":"easy","category":"bit","problem":"Every element appears twice except one. Find the single element using XOR.","signature":"def single_number(nums: list[int]) -> int:","reasoning":"XOR cancels pairs. The remaining value is the single number.","code":"def single_number(nums: list[int]) -> int:\n x = 0\n for v in nums:\n x ^= v\n return x\n","tests":[{"input":{"nums":[12,12,1,10,22,10,22,1,23,23,68]},"output":68},{"input":{"nums":[49,6,11,11,12,15,6,14,15,12,14]},"output":49},{"input":{"nums":[16,59,22,15,15,22,14,14,16]},"output":59}],"verified":true,"language":"python","code_hash":"f76c1da3c46d529e","sft_text":"### Problem\nEvery element appears twice except one. Find the single element using XOR.\n\n### Reasoning\nXOR cancels pairs. The remaining value is the single number.\n\n### Solution\n```python\ndef single_number(nums: list[int]) -> int:\n x = 0\n for v in nums:\n x ^= v\n return x\n```","meta":{"v":"ok"}}
23
+ {"id":"vcr_c5868f2562a8","difficulty":"easy","category":"array","problem":"Rotate nums to the right by k steps (k may be larger than n). Return a new list.","signature":"def rotate(nums: list[int], k: int) -> list[int]:","reasoning":"Reduce k modulo n. Last k elements move to the front.","code":"def rotate(nums: list[int], k: int) -> list[int]:\n n = len(nums)\n k %= n\n if k == 0:\n return list(nums)\n return nums[-k:] + nums[:-k]\n","tests":[{"input":{"nums":[18,10,12,-11,-17,8,-14,1,-15],"k":16},"output":[12,-11,-17,8,-14,1,-15,18,10]},{"input":{"nums":[-9,-3,4,4,6],"k":16},"output":[6,-9,-3,4,4]},{"input":{"nums":[1,1,-1,2,3],"k":10},"output":[1,1,-1,2,3]}],"verified":true,"language":"python","code_hash":"132c4800a39464fd","sft_text":"### Problem\nRotate nums to the right by k steps (k may be larger than n). Return a new list.\n\n### Reasoning\nReduce k modulo n. Last k elements move to the front.\n\n### Solution\n```python\ndef rotate(nums: list[int], k: int) -> list[int]:\n n = len(nums)\n k %= n\n if k == 0:\n return list(nums)\n return nums[-k:] + nums[:-k]\n```","meta":{"v":"ok"}}
24
+ {"id":"vcr_b57e3f3b828a","difficulty":"easy","category":"string","problem":"Reverse the order of words in s (words separated by single spaces).","signature":"def reverse_words(s: str) -> str:","reasoning":"Split on whitespace, reverse the list, join with spaces.","code":"def reverse_words(s: str) -> str:\n return ' '.join(reversed(s.split()))\n","tests":[{"input":{"s":"acacba cbace bdd bbadac"},"output":"bbadac bdd cbace acacba"},{"input":{"s":"a b bbb"},"output":"bbb b a"},{"input":{"s":"bb b"},"output":"b bb"}],"verified":true,"language":"python","code_hash":"e27e5a0fb61b865a","sft_text":"### Problem\nReverse the order of words in s (words separated by single spaces).\n\n### Reasoning\nSplit on whitespace, reverse the list, join with spaces.\n\n### Solution\n```python\ndef reverse_words(s: str) -> str:\n return ' '.join(reversed(s.split()))\n```","meta":{"v":"ok"}}
25
+ {"id":"vcr_b9e83b93d855","difficulty":"medium","category":"hashmap","problem":"Return ascending indices of the two numbers in nums that add up to target. Exactly one solution exists.","signature":"def two_sum(nums: list[int], target: int) -> list[int]:","reasoning":"1) Find i, j with nums[i] + nums[j] = target.\n2) Store value to index in a hash map while scanning.\n3) For each x, look up target - x; if present, return sorted indices.\n4) Time O(n), space O(n).","code":"def two_sum(nums: list[int], target: int) -> list[int]:\n seen = {}\n for i, x in enumerate(nums):\n need = target - x\n if need in seen:\n a, b = seen[need], i\n return [a, b] if a < b else [b, a]\n seen[x] = i\n return []\n","tests":[{"input":{"nums":[9,-10,17,56,-6,2,-2,34],"target":26},"output":[0,2]},{"input":{"nums":[0,-23,-15,29,9,-10,21,34,45],"target":-14},"output":[1,4]},{"input":{"nums":[48,-2,49,-13,31,-11,28,17,23],"target":40},"output":[7,8]}],"verified":true,"language":"python","code_hash":"98882f4a63a35075","sft_text":"### Problem\nReturn ascending indices of the two numbers in nums that add up to target. Exactly one solution exists.\n\n### Reasoning\n1) Find i, j with nums[i] + nums[j] = target.\n2) Store value to index in a hash map while scanning.\n3) For each x, look up target - x; if present, return sorted indices.\n4) Time O(n), space O(n).\n\n### Solution\n```python\ndef two_sum(nums: list[int], target: int) -> list[int]:\n seen = {}\n for i, x in enumerate(nums):\n need = target - x\n if need in seen:\n a, b = seen[need], i\n return [a, b] if a < b else [b, a]\n seen[x] = i\n return []\n```","meta":{"v":"ok"}}