code_quiz / example.json
burtenshaw
first commit
6f46aeb
[
{
"challenge": "Complete the function to calculate the factorial of a number using recursion",
"solution": "if n <= 1:\n return 1\nreturn n * factorial(n-1)",
"placeholder": "def factorial(n):\n # TODO: Implement recursive factorial calculation\n pass",
"context": "Factorial is the product of all positive integers less than or equal to n. For example, factorial(5) = 5 * 4 * 3 * 2 * 1 = 120. Base case is n=1 or n=0 which returns 1."
},
{
"challenge": "Implement a function to reverse a string without using built-in reverse methods",
"solution": "reversed_str = ''\nfor i in range(len(s)-1, -1, -1):\n reversed_str += s[i]\nreturn reversed_str",
"placeholder": "def reverse_string(s):\n # TODO: Implement string reversal\n pass",
"context": "String reversal can be done by iterating from the end to the beginning or using slicing with a negative step. This tests understanding of string manipulation and iteration."
},
{
"challenge": "Write a list comprehension that filters out all even numbers from the input list",
"solution": "return [num for num in numbers if num % 2 != 0]",
"placeholder": "def get_odd_numbers(numbers):\n # TODO: Filter odd numbers using list comprehension\n pass",
"context": "List comprehensions provide a concise way to create lists based on existing lists. The modulo operator % is used to test for odd/even numbers."
},
{
"challenge": "Complete the function to find the first non-repeating character in a string",
"solution": "char_count = {}\nfor char in s:\n char_count[char] = char_count.get(char, 0) + 1\nfor char in s:\n if char_count[char] == 1:\n return char\nreturn None",
"placeholder": "def first_non_repeating(s):\n # TODO: Find first non-repeating character\n pass",
"context": "This problem tests dictionary usage and string iteration. The solution involves counting character frequencies and then finding the first character with count 1."
},
{
"challenge": "Implement a function that checks if a string is a valid palindrome",
"solution": "s = ''.join(char.lower() for char in s if char.isalnum())\nreturn s == s[::-1]",
"placeholder": "def is_palindrome(s):\n # TODO: Check if string is palindrome (ignoring spaces and punctuation)\n pass",
"context": "Palindrome check requires string cleaning (removing spaces/punctuation), case normalization, and comparison. String slicing with [::-1] provides an efficient way to reverse strings in Python."
}
]