File size: 2,873 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
cases:
  - id: "sort_slice"
    question: "Create a function that sorts a slice of integers in ascending order"
    reference_code:
      go: |
        func SortSlice(slice []int) []int {
            sort.Ints(slice)
            return slice
        }
    difficulty: "easy"
    description: "Basic sorting function"
    
  - id: "binary_search"
    question: "Implement binary search algorithm for a sorted slice"
    reference_code:
      go: |
        func BinarySearch(slice []int, target int) int {
            left, right := 0, len(slice)-1
            for left <= right {
                mid := (left + right) / 2
                if slice[mid] == target {
                    return mid
                } else if slice[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:
      go: |
        func Fibonacci(n int) int {
            if n <= 1 {
                return n
            }
            a, b := 0, 1
            for i := 2; i <= n; i++ {
                a, b = b, a+b
            }
            return b
        }
    difficulty: "easy"
    description: "Fibonacci sequence"
    
  - id: "two_sum"
    question: "Find two numbers in a slice that add up to a target sum"
    reference_code:
      go: |
        func TwoSum(nums []int, target int) []int {
            seen := make(map[int]int)
            for i, num := range nums {
                complement := target - num
                if idx, exists := seen[complement]; exists {
                    return []int{idx, i}
                }
                seen[num] = i
            }
            return []int{}
        }
    difficulty: "medium"
    description: "Two sum problem"
    
  - id: "http_handler"
    question: "Create an HTTP handler that returns JSON response with user data"
    reference_code:
      go: |
        func GetUserHandler(w http.ResponseWriter, r *http.Request) {
            user := User{ID: 1, Name: "John Doe", Email: "john@example.com"}
            w.Header().Set("Content-Type", "application/json")
            json.NewEncoder(w).Encode(user)
        }
    difficulty: "medium"
    description: "HTTP handler with JSON response"
    
  - id: "concurrent_worker"
    question: "Create a worker pool that processes jobs concurrently using goroutines"
    reference_code:
      go: |
        func WorkerPool(jobs <-chan Job, results chan<- Result) {
            for job := range jobs {
                result := processJob(job)
                results <- result
            }
        }
    difficulty: "hard"
    description: "Concurrent programming with goroutines"