Spaces:
Sleeping
Sleeping
| 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" | |