go:interview:live_coding_test
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| go:interview:live_coding_test [2026/01/31 01:19] – phong2018 | go:interview:live_coding_test [2026/01/31 01:22] (current) – phong2018 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ====== Golang Live Coding |
| - | This document contains 5 live coding interview tests for Senior Golang developers, focused on concurrency, system design, and real-world Go usage. | + | This exam evaluates fundamental Go skills, basic concurrency, |
| - | ===== 1. Worker Pool with Goroutines and Channels ===== | + | Time suggestion: 45–60 minutes |
| - | ==== Problem | + | ===== Test 1: Sum of Integers ===== |
| - | Create a program that: | + | |
| - | Receives | + | ==== Question ==== |
| + | Write a function that receives | ||
| - | Starts N worker goroutines | + | ==== Input ==== |
| + | < | ||
| + | [1, 2, 3, 4, 5] | ||
| + | </ | ||
| - | Each worker processes jobs concurrently | + | ==== Output ==== |
| + | < | ||
| + | 15 | ||
| + | </ | ||
| - | Each job simulates work using time.Sleep | + | ==== Constraints ==== |
| - | Each job returns jobID * 2 | + | Do not use external libraries |
| - | Collects results safely (no data race) | + | Must handle empty slices |
| - | ==== What This Tests ==== | + | ==== Evaluation Criteria |
| - | Goroutines and channels | + | Correct result |
| - | sync.WaitGroup | + | Clean and readable code |
| - | Worker pool pattern | + | Proper function signature |
| - | Concurrency safety | + | ==== Notes ==== |
| + | |||
| + | Slice /slaɪs/: dynamic array in Go | ||
| + | |||
| + | ===== Test 2: Word Frequency Counter ===== | ||
| + | |||
| + | ==== Question ==== | ||
| + | Given a string, count how many times each word appears. | ||
| + | |||
| + | Words are separated by spaces. | ||
| + | |||
| + | ==== Input ==== | ||
| + | < | ||
| + | "go is fun and go is fast" | ||
| + | </ | ||
| + | |||
| + | ==== Output ==== | ||
| + | < | ||
| + | go: 2 | ||
| + | is: 2 | ||
| + | fun: 1 | ||
| + | and: 1 | ||
| + | fast: 1 | ||
| + | </ | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | Case-sensitive | ||
| + | |||
| + | Use built-in data structures only | ||
| - | ==== Senior-Level Extensions | + | ==== Evaluation Criteria |
| - | Add context.Context to cancel all workers | + | Correct map usage |
| - | Add per-job timeout | + | Proper string manipulation |
| - | Graceful worker shutdown | + | Clean iteration logic |
| ==== Notes ==== | ==== Notes ==== | ||
| - | Worker pool /ˈwɜːrkər puːl/: a fixed number of workers processing tasks from a queue | + | Map /mæp/: key-value data structure |
| - | Goroutine | + | Iteration |
| - | Data race /ˈdeɪtə reɪs/: concurrent access to shared data without synchronization | + | ===== Test 3: Filter Even Numbers ===== |
| - | ===== 2. Rate Limiter (Token Bucket) ===== | + | ==== Question |
| + | Write a function that returns only even numbers from a list. | ||
| - | ==== Problem | + | ==== Input ==== |
| - | Implement a rate limiter that: | + | < |
| + | [1, 2, 3, 4, 5, 6] | ||
| + | </ | ||
| - | Allows at most X requests per second | + | ==== Output ==== |
| + | < | ||
| + | [2, 4, 6] | ||
| + | </ | ||
| - | Rejects or blocks requests when the limit is exceeded | + | ==== Constraints ==== |
| - | Is safe for concurrent access | + | Maintain input order |
| - | ==== What This Tests ==== | + | No global variables |
| - | Time-based logic | + | ==== Evaluation Criteria ==== |
| - | Concurrent-safe design | + | Correct condition logic |
| - | Understanding of rate-limiting algorithms | + | Proper slice handling |
| - | ==== Senior-Level Extensions | + | ==== Notes ==== |
| - | Support burst traffic | + | Even number /ˈiːvən ˈnʌmbər/: |
| - | Use time.Ticker | + | ===== Test 4: Goroutine with Channel ===== |
| - | Make limits configurable at runtime | + | ==== Question ==== |
| + | Create a goroutine that sends numbers from 1 to 3 into a channel. | ||
| + | The main function must receive and print them. | ||
| + | |||
| + | ==== Input ==== | ||
| + | < | ||
| + | 1, 2, 3 | ||
| + | </ | ||
| + | |||
| + | ==== Output ==== | ||
| + | < | ||
| + | 1 | ||
| + | 2 | ||
| + | 3 | ||
| + | </ | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | Must use one goroutine | ||
| + | |||
| + | Channel must be closed properly | ||
| + | |||
| + | ==== Evaluation Criteria ==== | ||
| + | |||
| + | Correct goroutine usage | ||
| + | |||
| + | Proper channel closing | ||
| + | |||
| + | No deadlocks | ||
| ==== Notes ==== | ==== Notes ==== | ||
| - | Rate limiter | + | Goroutine |
| - | Token bucket | + | Deadlock |
| - | Burst /bɜːrst/: many requests arriving at once | + | ===== Test 5: Simple HTTP Handler ===== |
| - | ===== 3. Concurrent URL Fetcher ===== | + | ==== Question |
| + | Create an HTTP server that: | ||
| - | ==== Problem ==== | + | Listens on port 8080 |
| - | Write a function that: | + | |
| - | Accepts a list of URLs | + | Responds "Hello Go" to /hello |
| - | Fetches them concurrently | + | ==== Input ==== |
| + | < | ||
| + | GET /hello | ||
| + | </ | ||
| - | Limits concurrency to N requests at a time | + | ==== Output ==== |
| + | < | ||
| + | Hello Go | ||
| + | </ | ||
| - | Returns results and errors separately | + | ==== Constraints ==== |
| - | ==== What This Tests ==== | + | Use net/http |
| - | Fan-out / fan-in concurrency pattern | + | No third-party libraries |
| - | Error handling in concurrent systems | + | ==== Evaluation Criteria ==== |
| - | Goroutine coordination | + | Correct handler implementation |
| - | ==== Senior-Level Extensions ==== | + | Proper server startup |
| - | Retry failed requests with backoff | + | Clean code structure |
| - | Cancel remaining requests on fatal error | + | ==== Notes ==== |
| - | Add request timeout using context | + | HTTP handler /ˌeɪtʃ tiː tiː piː ˈhændlər/: |
| + | |||
| + | ====== Senior Golang Live Coding Exam ====== | ||
| + | |||
| + | This exam contains 5 live coding tests for Senior Golang developers. | ||
| + | Candidates are expected to write correct, concurrent-safe, | ||
| + | |||
| + | Time suggestion: 60–90 minutes | ||
| + | |||
| + | ===== Test 1: Worker Pool Processing ===== | ||
| + | |||
| + | ==== Question ==== | ||
| + | You are given a list of jobs represented by integers. | ||
| + | Create a worker pool with N workers that processes the jobs concurrently. | ||
| + | |||
| + | Each job must: | ||
| + | |||
| + | Sleep for 100ms | ||
| + | |||
| + | Return jobID * 2 | ||
| + | |||
| + | The program must print the result for each job. | ||
| + | |||
| + | ==== Input ==== | ||
| + | |||
| + | jobs = [1, 2, 3, 4, 5] | ||
| + | |||
| + | workers = 2 | ||
| + | |||
| + | ==== Output ==== | ||
| + | Order does NOT matter. | ||
| + | |||
| + | < | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | Must use goroutines and channels | ||
| + | |||
| + | Must not have data races | ||
| + | |||
| + | Workers must exit cleanly | ||
| + | |||
| + | ==== Evaluation Criteria ==== | ||
| + | |||
| + | Correct concurrency model | ||
| + | |||
| + | No race conditions | ||
| + | |||
| + | Clean shutdown logic | ||
| ==== Notes ==== | ==== Notes ==== | ||
| - | Fan-out | + | Worker pool /ˈwɜːrkər puːl/: group of workers processing tasks |
| - | Backoff | + | Data race /ˈdeɪtə reɪs/: unsafe concurrent memory access |
| - | Concurrency limit / | + | ===== Test 2: Rate Limiter ===== |
| - | ===== 4. Thread-Safe In-Memory Cache with TTL ===== | + | ==== Question |
| + | Implement a rate limiter that allows at most 2 requests per second. | ||
| - | ==== Problem ==== | + | Each call to Allow() returns: |
| - | Implement an in-memory cache that: | + | |
| - | Stores key-value pairs | + | true if the request is allowed |
| - | Supports TTL (time to live) | + | false otherwise |
| - | Is safe for concurrent reads and writes | + | ==== Input ==== |
| + | Call times (milliseconds): | ||
| - | ==== What This Tests ==== | + | < |
| - | sync.Mutex | + | ==== Output ==== |
| + | < | ||
| + | true | ||
| + | true | ||
| + | false | ||
| + | false | ||
| + | false | ||
| + | </code> | ||
| - | Data consistency | + | ==== Constraints ==== |
| - | Time-based expiration | + | Must be safe for concurrent use |
| - | ==== Senior-Level Extensions ==== | + | Must rely on time-based logic |
| - | Background cleanup goroutine | + | Busy-waiting is not allowed |
| - | LRU eviction strategy | + | ==== Evaluation Criteria ==== |
| - | Cache hit/miss metrics | + | Correct rate limiting |
| + | |||
| + | Thread-safe implementation | ||
| + | |||
| + | Efficient time handling | ||
| ==== Notes ==== | ==== Notes ==== | ||
| - | TTL (Time To Live) /ˌtiː tiː ˈɛl/: how long data remains valid | + | Rate limiter |
| - | Eviction | + | Busy-waiting |
| - | Thread-safe /θred seɪf/: safe for concurrent access | + | ===== Test 3: Concurrent URL Fetcher ===== |
| - | ===== 5. Graceful HTTP Server Shutdown ===== | + | ==== Question |
| + | Write a function that fetches multiple URLs concurrently, | ||
| - | ==== Problem | + | ==== Input ==== |
| - | Create an HTTP server that: | + | |
| - | Handles requests normally | + | URLs: |
| - | Listens for OS signals (SIGINT, SIGTERM) | + | < |
| - | Shuts down gracefully without dropping in-flight requests | + | https:// |
| - | ==== What This Tests ==== | + | https:// |
| - | Real-world Go server handling | + | https:// |
| - | Signal handling | + | </ |
| - | http.Server.Shutdown | + | Max concurrency = 2 |
| - | ==== Senior-Level Extensions | + | ==== Output |
| + | < | ||
| + | success: https:// | ||
| - | Add shutdown timeout | + | success: https:// |
| - | Log active connections | + | success: https:// |
| - | Cancel request contexts on shutdown | + | </ |
| + | |||
| + | (Order does NOT matter) | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | At most 2 HTTP requests at the same time | ||
| + | |||
| + | Must wait for all requests to finish | ||
| + | |||
| + | Errors must not crash the program | ||
| + | |||
| + | ==== Evaluation Criteria ==== | ||
| + | |||
| + | Correct concurrency limit | ||
| + | |||
| + | Proper error handling | ||
| + | |||
| + | No goroutine leaks | ||
| ==== Notes ==== | ==== Notes ==== | ||
| - | Graceful shutdown | + | Concurrency limit /kənˈkʌrənsi ˈlɪmɪt/: maximum parallel tasks |
| + | |||
| + | Goroutine leak /ˌɡoʊˈruːtiːn liːk/: goroutine that never exits | ||
| + | |||
| + | ===== Test 4: Thread-Safe Cache with TTL ===== | ||
| + | |||
| + | ==== Question ==== | ||
| + | Implement an in-memory cache with expiration support. | ||
| + | |||
| + | Each key: | ||
| + | |||
| + | Has a value | ||
| + | |||
| + | Expires after TTL (seconds) | ||
| + | |||
| + | ==== Input ==== | ||
| + | < | ||
| + | Set(" | ||
| + | Get(" | ||
| + | Get(" | ||
| + | </ | ||
| + | |||
| + | ==== Output ==== | ||
| + | < | ||
| + | 1 | ||
| + | nil | ||
| + | </ | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | Concurrent access must be safe | ||
| + | |||
| + | Expired keys must not be returned | ||
| + | |||
| + | No global variables | ||
| + | |||
| + | ==== Evaluation Criteria ==== | ||
| + | |||
| + | Correct TTL handling | ||
| + | |||
| + | Proper locking strategy | ||
| + | |||
| + | Clean code structure | ||
| + | |||
| + | ==== Notes ==== | ||
| + | |||
| + | TTL (Time To Live) /ˌtiː tiː ˈɛl/: duration data is valid | ||
| + | |||
| + | Thread-safe /θred seɪf/: safe for concurrent use | ||
| + | |||
| + | ===== Test 5: Graceful HTTP Server Shutdown ===== | ||
| + | |||
| + | ==== Question ==== | ||
| + | Create an HTTP server that: | ||
| + | |||
| + | Listens on port 8080 | ||
| + | |||
| + | Responds " | ||
| + | |||
| + | Shuts down gracefully on SIGINT | ||
| + | |||
| + | ==== Input ==== | ||
| + | |||
| + | HTTP request: GET /health | ||
| + | |||
| + | OS signal: SIGINT | ||
| + | |||
| + | ==== Output ==== | ||
| + | < | ||
| + | OK | ||
| + | Server shutdown completed | ||
| + | </ | ||
| + | |||
| + | ==== Constraints ==== | ||
| + | |||
| + | In-flight requests must complete | ||
| + | |||
| + | Shutdown timeout must be handled | ||
| + | |||
| + | No forced exit (os.Exit) | ||
| + | |||
| + | ==== Evaluation Criteria ==== | ||
| + | |||
| + | Proper signal handling | ||
| + | |||
| + | Correct use of http.Server.Shutdown | ||
| + | |||
| + | Clean resource release | ||
| + | |||
| + | ==== Notes ==== | ||
| - | In-flight request | + | Graceful shutdown |
| - | Signal handling | + | In-flight request |
go/interview/live_coding_test.1769822378.txt.gz · Last modified: by phong2018
