[
  {"id": "cb-01", "name": "merge_half_open",
   "prompt": "Write a Python function `merge_half_open(intervals)` that takes a list of [start, end) half-open integer intervals and returns the merged list sorted by start. Touching intervals merge: [1,4) and [4,7) become [1,7). Return a list of [start, end) lists.\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert merge_half_open([[1,4],[4,7],[9,10]]) == [[1,7],[9,10]]",
     "assert merge_half_open([]) == []",
     "assert merge_half_open([[5,6],[1,2],[2,3]]) == [[1,3],[5,6]]",
     "assert merge_half_open([[1,10],[2,3],[4,5]]) == [[1,10]]",
     "assert merge_half_open([[3,4],[1,2]]) == [[1,2],[3,4]]"
   ]},

  {"id": "cb-02", "name": "rle_decode",
   "prompt": "Write a Python function `rle_decode(pairs)` that decodes a run-length encoding given as a list of (character, count) tuples into a string. If any count is negative or any character is not a single-character string, raise ValueError.\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert rle_decode([('a',3),('b',1),('c',2)]) == 'aabcc'",
     "assert rle_decode([]) == ''",
     "assert rle_decode([('x',0),('y',2)]) == 'yy'",
     "import pytest\ndef _raises():\n    try:\n        rle_decode([('ab',2)]); return False\n    except ValueError:\n        return True\nassert _raises()",
     "def _raises2():\n    try:\n        rle_decode([('a',-1)]); return False\n    except ValueError:\n        return True\nassert _raises2()"
   ]},

  {"id": "cb-03", "name": "top_k_words",
   "prompt": "Write a Python function `top_k_words(text, k)` returning the k most frequent words in `text`. Words are maximal runs of ASCII letters, compared case-insensitively and returned lowercased. Ties break alphabetically. If k <= 0 return [].\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert top_k_words('Dog cat dog CAT bird dog cat', 2) == ['cat', 'dog']",
     "assert top_k_words('a b c', 5) == ['a', 'b', 'c']",
     "assert top_k_words('Hello, HELLO! world... World?', 2) == ['hello', 'world']",
     "assert top_k_words('same same', 0) == []",
     "assert top_k_words('b2b b c3c c c', 1) == ['c']"
   ]},

  {"id": "cb-04", "name": "spiral_coords",
   "prompt": "Write a Python function `spiral_coords(rows, cols)` that returns the coordinates (row, col) of an rows-by-cols grid in clockwise spiral order starting at (0,0), moving right first. Return a list of tuples.\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert spiral_coords(1, 3) == [(0,0),(0,1),(0,2)]",
     "assert spiral_coords(3, 1) == [(0,0),(1,0),(2,0)]",
     "assert spiral_coords(2, 2) == [(0,0),(0,1),(1,1),(1,0)]",
     "assert spiral_coords(3, 3) == [(0,0),(0,1),(0,2),(1,2),(2,2),(2,1),(2,0),(1,0),(1,1)]",
     "assert spiral_coords(0, 5) == []"
   ]},

  {"id": "cb-05", "name": "min_bracket_removals",
   "prompt": "Write a Python function `min_bracket_removals(s)` returning the minimum number of characters to remove from string `s` (which contains only '(' , ')' and lowercase letters) so that the remaining parentheses are balanced. Letters are never removed.\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert min_bracket_removals('a(b)c') == 0",
     "assert min_bracket_removals('(()') == 1",
     "assert min_bracket_removals('))((') == 4",
     "assert min_bracket_removals(')a(b)c(') == 2",
     "assert min_bracket_removals('') == 0"
   ]},

  {"id": "cb-06", "name": "ttl_cache",
   "prompt": "Write a Python class `TTLCache` with methods `put(key, value, ttl)` and `get(key)`. `get` returns the value or None if missing or expired. Expiry is computed against an injectable clock: the constructor takes `now` (a callable returning float seconds). Do not use time.time() except via the injected clock.\n\nReturn ONLY a single ```python fenced code block with the complete class, no explanation, no tests.",
   "tests": [
     "t = [100.0]\nc = TTLCache(now=lambda: t[0])\nc.put('a', 1, ttl=10)\nassert c.get('a') == 1\nt[0] = 109.9\nassert c.get('a') == 1\nt[0] = 110.0\nassert c.get('a') is None",
     "t2 = [0.0]\nc2 = TTLCache(now=lambda: t2[0])\nc2.put('x', 'v', ttl=5)\nc2.put('x', 'w', ttl=50)\nt2[0] = 10\nassert c2.get('x') == 'w'",
     "t3 = [0.0]\nc3 = TTLCache(now=lambda: t3[0])\nassert c3.get('missing') is None"
   ]},

  {"id": "cb-07", "name": "log_buckets",
   "prompt": "Write a Python function `count_per_hour(lines)` that takes log lines of the form 'YYYY-MM-DDTHH:MM:SS LEVEL message' and returns a dict mapping 'YYYY-MM-DDTHH' to the count of ERROR lines in that hour. Malformed lines are skipped. Only level ERROR counts.\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert count_per_hour(['2026-08-27T03:10:00 ERROR disk full', '2026-08-27T03:55:59 INFO ok', '2026-08-27T03:59:00 ERROR again']) == {'2026-08-27T03': 2}",
     "assert count_per_hour(['garbage line', '2026-08-27T04:00:00 WARN w']) == {}",
     "assert count_per_hour(['2026-08-27T04:01:00 ERROR a', '2026-08-28T04:02:00 ERROR b']) == {'2026-08-27T04': 1, '2026-08-28T04': 1}",
     "assert count_per_hour([]) == {}"
   ]},

  {"id": "cb-08", "name": "water_per_index",
   "prompt": "Write a Python function `water_per_index(height)` that, given a list of non-negative integer elevations, returns a list `w` of the same length where w[i] is the units of water trapped above index i after rain (classic trapping rain water, but per-index instead of the total).\n\nReturn ONLY a single ```python fenced code block with the complete function, no explanation, no tests.",
   "tests": [
     "assert water_per_index([0,1,0,2,1,0,1,3,2,1,2,1]) == [0,0,1,0,1,2,1,0,0,1,0,0]",
     "assert water_per_index([]) == []",
     "assert water_per_index([3,3,3]) == [0,0,0]",
     "assert water_per_index([2,0,2]) == [0,2,0]",
     "assert water_per_index([1,2,3,4]) == [0,0,0,0]"
   ]}
]
