File size: 3,401 Bytes
acd8e16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
cases:
  - id: "sort_list"
    question: "Create a function that sorts a list of integers in ascending order"
    reference_code:
      python: |
        def sort_list(numbers):
            return sorted(numbers)
    difficulty: "easy"
    description: "Basic sorting function"
    
  - id: "binary_search"
    question: "Implement binary search algorithm for a sorted list"
    reference_code:
      python: |
        def binary_search(arr, target):
            left, right = 0, len(arr) - 1
            while left <= right:
                mid = (left + right) // 2
                if arr[mid] == target:
                    return mid
                elif arr[mid] < target:
                    left = mid + 1
                else:
                    right = mid - 1
            return -1
    difficulty: "medium"
    description: "Binary search algorithm"
    
  - id: "fibonacci"
    question: "Create a function that returns the nth Fibonacci number"
    reference_code:
      python: |
        def fibonacci(n):
            if n <= 1:
                return n
            a, b = 0, 1
            for _ in range(2, n + 1):
                a, b = b, a + b
            return b
    difficulty: "easy"
    description: "Fibonacci sequence"
    
  - id: "two_sum"
    question: "Find two numbers in a list that add up to a target sum"
    reference_code:
      python: |
        def two_sum(nums, target):
            seen = {}
            for i, num in enumerate(nums):
                complement = target - num
                if complement in seen:
                    return [seen[complement], i]
                seen[num] = i
            return []
    difficulty: "medium"
    description: "Two sum problem"
    
  - id: "merge_sort"
    question: "Implement merge sort algorithm"
    reference_code:
      python: |
        def merge_sort(arr):
            if len(arr) <= 1:
                return arr
            mid = len(arr) // 2
            left = merge_sort(arr[:mid])
            right = merge_sort(arr[mid:])
            return merge(left, right)
        
        def merge(left, right):
            result = []
            i = j = 0
            while i < len(left) and j < len(right):
                if left[i] <= right[j]:
                    result.append(left[i])
                    i += 1
                else:
                    result.append(right[j])
                    j += 1
            result.extend(left[i:])
            result.extend(right[j:])
            return result
    difficulty: "hard"
    description: "Merge sort implementation"
    
  - id: "class_implementation"
    question: "Create a class for a bank account with deposit and withdraw methods"
    reference_code:
      python: |
        class BankAccount:
            def __init__(self, initial_balance=0):
                self.balance = initial_balance
            
            def deposit(self, amount):
                if amount > 0:
                    self.balance += amount
                    return True
                return False
            
            def withdraw(self, amount):
                if 0 < amount <= self.balance:
                    self.balance -= amount
                    return True
                return False
            
            def get_balance(self):
                return self.balance
    difficulty: "medium"
    description: "Object-oriented programming"