name stringlengths 3 20 | target_function_name stringlengths 3 20 | signature stringlengths 24 53 | description stringlengths 41 169 | difficulty stringclasses 3
values | source_code stringlengths 124 587 | edge_cases_json stringlengths 33 125 | fuzz_spec_json stringlengths 37 170 |
|---|---|---|---|---|---|---|---|
fibonacci | fibonacci | fibonacci(n: int) -> int | Returns the n-th Fibonacci number. Raises ValueError for invalid n (n must be a positive int <= 90). | easy | def fibonacci(n):
if not isinstance(n, int) or isinstance(n, bool) or n <= 0 or n > 90:
raise ValueError('Input must be a positive integer <= 90.')
a, b = 0, 1
for _ in range(n - 1):
a, b = b, a + b
return b if n > 0 else a
| ["1", "2", "3", "10", "89", "90"] | {"n": {"type": "int", "min": 1, "max": 90}} |
reverse_string | reverse_string | reverse_string(s: str) -> str | Returns the reversed string. Raises TypeError for non-str. | easy | def reverse_string(s):
if not isinstance(s, str):
raise TypeError('Input must be a string.')
return s[::-1]
| ["\"\"", "\"a\"", "\"ab\"", "\"racecar\"", "\"Hello, World!\""] | {"s": {"type": "str", "max_len": 12}} |
is_palindrome | is_palindrome | is_palindrome(s: str) -> bool | Case-insensitive palindrome check, ignoring non-alphanumeric characters. Raises TypeError for non-str. | medium | def is_palindrome(s):
if not isinstance(s, str):
raise TypeError('Input must be a string.')
cleaned = ''.join(ch.lower() for ch in s if ch.isalnum())
return cleaned == cleaned[::-1]
| ["\"\"", "\"a\"", "\"ab\"", "\"abba\"", "\"A man, a plan, a canal: Panama\"", "\"Hello\""] | {"s": {"type": "str", "max_len": 12}} |
digit_sum | digit_sum | digit_sum(n: int) -> int | Sum of the decimal digits of n. n must be a non-negative int. | easy | def digit_sum(n):
if not isinstance(n, int) or isinstance(n, bool):
raise TypeError('Input must be int.')
if n < 0:
raise ValueError('Input must be non-negative.')
return sum(int(c) for c in str(n))
| ["0", "1", "9", "10", "99", "100", "9999"] | {"n": {"type": "int", "min": 0, "max": 10000}} |
count_vowels | count_vowels | count_vowels(s: str) -> int | Count of vowels (a/e/i/o/u, case-insensitive) in s. | easy | def count_vowels(s):
if not isinstance(s, str):
raise TypeError('Input must be a string.')
return sum(1 for c in s.lower() if c in 'aeiou')
| ["\"\"", "\"bcd\"", "\"AEIOU\"", "\"Hello, World!\"", "\"aaaaa\""] | {"s": {"type": "str", "max_len": 16}} |
gcd | gcd | gcd(pair: tuple[int, int] | list[int]) -> int | Greatest common divisor of a 2-element tuple/list of non-negative ints. | medium | def gcd(pair):
if not isinstance(pair, (list, tuple)) or len(pair) != 2:
raise TypeError('Input must be a 2-element list or tuple.')
a, b = pair
if not all(isinstance(x, int) and not isinstance(x, bool) for x in (a, b)):
raise TypeError('Both elements must be int.')
if a < 0 or b < 0:
... | ["(0, 0)", "(0, 7)", "(12, 18)", "(17, 13)", "(100, 75)"] | {"pair": {"type": "tuple", "elems": [{"type": "int", "min": 0, "max": 1000}, {"type": "int", "min": 0, "max": 1000}]}} |
sort_unique | sort_unique | sort_unique(xs: list[int]) -> list[int] | Sorted, deduplicated list of ints from xs. | easy | def sort_unique(xs):
if not isinstance(xs, list):
raise TypeError('Input must be a list.')
if not all(isinstance(x, int) and not isinstance(x, bool) for x in xs):
raise TypeError('All elements must be int.')
return sorted(set(xs))
| ["[]", "[1]", "[1, 1, 1]", "[3, 1, 2]", "[-5, 5, 0, -5, 5]"] | {"xs": {"type": "list", "elem": {"type": "int", "min": -50, "max": 50}, "max_len": 8}} |
caesar_cipher | caesar_cipher | caesar_cipher(s: str) -> str | Caesar shift by +3 on lowercase letters; non-lowercase chars are unchanged. | hard | def caesar_cipher(s):
if not isinstance(s, str):
raise TypeError('Input must be a string.')
out = []
for ch in s:
if 'a' <= ch <= 'z':
out.append(chr((ord(ch) - ord('a') + 3) % 26 + ord('a')))
else:
out.append(ch)
return ''.join(out)
| ["\"\"", "\"abc\"", "\"xyz\"", "\"Hello, World!\"", "\"ABC\"", "\"hello world\""] | {"s": {"type": "str", "max_len": 16}} |
is_prime | is_prime | is_prime(n: int) -> bool | True iff n is a prime int. n must be int. | medium | def is_prime(n):
if not isinstance(n, int) or isinstance(n, bool):
raise TypeError('Input must be int.')
if n < 2:
return False
if n < 4:
return True
if n % 2 == 0:
return False
i = 3
while i * i <= n:
if n % i == 0:
return False
i += 2... | ["0", "1", "2", "3", "4", "17", "25", "97", "100"] | {"n": {"type": "int", "min": 0, "max": 200}} |
roman_to_int | roman_to_int | roman_to_int(s: str) -> int | Parse a roman numeral string into its integer value. Raises ValueError for non-roman characters. Subtraction rules (IV=4, IX=9, XL=40, ...) are honoured. Empty -> 0. | medium | def roman_to_int(s: str) -> int:
if not isinstance(s, str):
raise TypeError('input must be str')
table = {'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}
total = 0
prev = 0
for ch in reversed(s.upper()):
if ch not in table:
raise ValueError(f'invalid roman numeral cha... | ["\"\"", "\"I\"", "\"IV\"", "\"IX\"", "\"LVIII\"", "\"MCMXCIV\"", "\"MMXXIV\""] | {"s": {"type": "str", "alphabet": "IVXLCDM", "max_len": 8}} |
levenshtein_distance | levenshtein_distance | levenshtein_distance(a: str, b: str) -> int | Classic edit distance between two strings: minimum number of single-character insertions, deletions, or substitutions to transform a into b. Both arguments must be str. | hard | def levenshtein_distance(a: str, b: str) -> int:
if not isinstance(a, str) or not isinstance(b, str):
raise TypeError('both arguments must be str')
if a == b:
return 0
if not a:
return len(b)
if not b:
return len(a)
prev = list(range(len(b) + 1))
for i, ca in enum... | ["(\"\", \"\")", "(\"a\", \"\")", "(\"\", \"a\")", "(\"kitten\", \"sitting\")", "(\"flaw\", \"lawn\")", "(\"abc\", \"abc\")"] | {"a": {"type": "str", "alphabet": "abc", "max_len": 6}, "b": {"type": "str", "alphabet": "abc", "max_len": 6}} |
flatten_list | flatten_list | flatten_list(xs: list) -> list | Recursively flatten a nested list of arbitrary depth. Tuples are also flattened; non-list/tuple atoms (ints, strs, ...) pass through unchanged. | medium | def flatten_list(xs):
if not isinstance(xs, (list, tuple)):
raise TypeError('input must be list or tuple')
out = []
stack = list(xs)
# iterative DFS to avoid recursion limits on adversarial input
rev = []
rev.extend(reversed(stack))
while rev:
x = rev.pop()
if isinsta... | ["[]", "[1]", "[[1, 2], [3, 4]]", "[1, [2, [3, [4, [5]]]]]", "[[], [], 1]"] | {"xs": {"type": "list", "elem": {"type": "int", "min": -10, "max": 10}, "max_len": 6}} |
merge_sorted | merge_sorted | merge_sorted(a: list[int], b: list[int]) -> list[int] | Merge two pre-sorted lists of ints into a single sorted list. Both arguments must be lists; elements must be ints (bools rejected). The classic merge step of merge-sort. | medium | def merge_sorted(a, b):
if not isinstance(a, list) or not isinstance(b, list):
raise TypeError('both arguments must be list')
for x in (*a, *b):
if not isinstance(x, int) or isinstance(x, bool):
raise TypeError('elements must be int')
out = []
i = j = 0
while i < len(a) a... | ["([], [])", "([1, 2, 3], [])", "([], [1, 2, 3])", "([1, 3, 5], [2, 4, 6])", "([1, 1], [1, 1])"] | {"a": {"type": "list", "elem": {"type": "int", "min": -20, "max": 20}, "max_len": 5}, "b": {"type": "list", "elem": {"type": "int", "min": -20, "max": 20}, "max_len": 5}} |
run_length_encode | run_length_encode | run_length_encode(s: str) -> list[tuple[str, int]] | Run-length encoding: returns a list of (character, count) tuples for each run of identical characters in s. Empty input yields an empty list. | easy | def run_length_encode(s):
if not isinstance(s, str):
raise TypeError('input must be str')
if not s:
return []
out = []
cur = s[0]
n = 1
for ch in s[1:]:
if ch == cur:
n += 1
else:
out.append((cur, n))
cur = ch
n = 1
... | ["\"\"", "\"a\"", "\"aa\"", "\"abc\"", "\"aaabbbccc\"", "\"aaaaaaaaaa\""] | {"s": {"type": "str", "alphabet": "ab", "max_len": 12}} |
binary_search | binary_search | binary_search(arr: list[int], target: int) -> int | Return the index of target in the sorted ascending list arr, or -1 if not present. arr must be a list of ints; target must be int. The list is assumed sorted. | medium | def binary_search(arr, target):
if not isinstance(arr, list):
raise TypeError('arr must be list')
if not isinstance(target, int) or isinstance(target, bool):
raise TypeError('target must be int')
lo, hi = 0, len(arr) - 1
while lo <= hi:
mid = (lo + hi) // 2
v = arr[mid]
... | ["([], 3)", "([1], 1)", "([1], 2)", "([1, 2, 3, 4, 5], 3)", "([1, 2, 3, 4, 5], 0)", "([1, 2, 3, 4, 5], 6)"] | {"arr": {"type": "list", "elem": {"type": "int", "min": -20, "max": 20}, "max_len": 8}, "target": {"type": "int", "min": -20, "max": 20}} |
README.md exists but content is empty.
- Downloads last month
- 28