User Tools

Site Tools


go:interview:live_coding_test

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
go:interview:live_coding_test [2026/01/31 01:19] phong2018go:interview:live_coding_test [2026/01/31 01:22] (current) phong2018
Line 1: Line 1:
-====== Senior Golang Live Coding Tests ======+====== Golang Live Coding Exam (Junior → Middle) ======
  
-This document contains 5 live coding interview tests for Senior Golang developersfocused on concurrency, system design, and real-world Go usage.+This exam evaluates fundamental Go skillsbasic concurrency, and clean coding.
  
-===== 1. Worker Pool with Goroutines and Channels =====+Time suggestion: 45–60 minutes
  
-==== Problem ==== +===== Test 1: Sum of Integers =====
-Create a program that:+
  
-Receives a list of jobs (integers)+==== Question ==== 
 +Write a function that receives a list of integers and returns their sum.
  
-Starts N worker goroutines+==== Input ==== 
 +<code> 
 +[1, 2, 3, 4, 5] 
 +</code>
  
-Each worker processes jobs concurrently+==== Output ==== 
 +<code> 
 +15 
 +</code>
  
-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 ==== 
 +<code> 
 +"go is fun and go is fast" 
 +</code> 
 + 
 +==== Output ==== 
 +<code> 
 +go: 2 
 +is: 2 
 +fun: 1 
 +and: 1 
 +fast: 1 
 +</code> 
 + 
 +==== 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 ɡoʊˈruːtiːn/: lightweight concurrent function in Go+Iteration ɪtəˈreɪʃən/: looping over data
  
-Data race /ˈdeɪtə reɪs/concurrent access to shared data without synchronization+===== Test 3Filter 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:+<code> 
 +[1, 2, 3, 4, 5, 6] 
 +</code>
  
-Allows at most X requests per second+==== Output ==== 
 +<code> 
 +[2, 4, 6] 
 +</code>
  
-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/: number divisible by 2
  
-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 ==== 
 +<code> 
 +1, 2, 3 
 +</code> 
 + 
 +==== Output ==== 
 +<code> 
 +
 +
 +
 +</code> 
 + 
 +==== Constraints ==== 
 + 
 +Must use one goroutine 
 + 
 +Channel must be closed properly 
 + 
 +==== Evaluation Criteria ==== 
 + 
 +Correct goroutine usage 
 + 
 +Proper channel closing 
 + 
 +No deadlocks
  
 ==== Notes ==== ==== Notes ====
  
-Rate limiter /reɪt ˈlɪmɪtər/: controls how often an action can occur+Goroutine /ˌɡoʊˈruːtiːn/: lightweight concurrent function
  
-Token bucket toʊkən ˈbʌkɪt/: algorithm that allows requests based on available tokens+Deadlock dɛdˌlɒk/: program waits forever
  
-Burst /bɜːrst/many requests arriving at once+===== Test 5Simple 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 ==== 
 +<code> 
 +GET /hello 
 +</code>
  
-Limits concurrency to N requests at a time+==== Output ==== 
 +<code> 
 +Hello Go 
 +</code>
  
-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/: function handling HTTP requests 
 + 
 +====== Senior Golang Live Coding Exam ====== 
 + 
 +This exam contains 5 live coding tests for Senior Golang developers. 
 +Candidates are expected to write correct, concurrent-safe, idiomatic Go code. 
 + 
 +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. 
 + 
 +<code> 2 4 6 8 10 </code> 
 + 
 +==== 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 Fan-in /fæn aʊt | fæn ɪn/: splitting work and merging results+Worker pool /ˈwɜːrkər puːl/: group of workers processing tasks
  
-Backoff bækˌɔːf/: increasing delay between retries+Data race deɪtə reɪs/: unsafe concurrent memory access
  
-Concurrency limit /kənˈkʌrənsi ˈlɪmɪt/maximum number of parallel tasks+===== Test 2Rate 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 ====+<code> 0ms 200ms 400ms 600ms 800ms </code>
  
-sync.Mutex sync.RWMutex+==== Output ==== 
 +<code> 
 +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 /reɪt ˈlɪmɪtər/: controls request frequency
  
-Eviction /ɪˈvɪkʃən/: removing old or expired data+Busy-waiting /ˈbɪzi ˈweɪtɪŋ/: wasting CPU while waiting
  
-Thread-safe /θred seɪf/safe for concurrent access+===== Test 3Concurrent URL Fetcher =====
  
-===== 5. Graceful HTTP Server Shutdown =====+==== Question ==== 
 +Write a function that fetches multiple URLs concurrently, but limits concurrency.
  
-==== Problem ==== +==== Input ====
-Create an HTTP server that:+
  
-Handles requests normally+URLs:
  
-Listens for OS signals (SIGINT, SIGTERM)+<code>
  
-Shuts down gracefully without dropping in-flight requests+https://example.com/a
  
-==== What This Tests ====+https://example.com/b
  
-Real-world Go server handling+https://example.com/c
  
-Signal handling+</code>
  
-http.Server.Shutdown+Max concurrency = 2
  
-==== Senior-Level Extensions ====+==== Output ==== 
 +<code> 
 +success: https://example.com/a
  
-Add shutdown timeout+success: https://example.com/b
  
-Log active connections+success: https://example.com/c
  
-Cancel request contexts on shutdown+</code> 
 + 
 +(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 /ˈɡreɪsfəˈʃʌtdaʊn/: stopping system without interrupting active work+Concurrency limit /kənˈkʌrənsi ˈlɪmɪt/: maximum parallel tasks 
 + 
 +Goroutine leak /ˌɡoʊˈruːtiː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 value 
 + 
 +Expires after TTL (seconds) 
 + 
 +==== Input ==== 
 +<code> 
 +Set("a", 1, ttl=1s) 
 +Get("a") -> after 500ms 
 +Get("a") -> after 1500ms 
 +</code> 
 + 
 +==== Output ==== 
 +<code> 
 +
 +nil 
 +</code> 
 + 
 +==== 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 "OK" to /health 
 + 
 +Shuts down gracefully on SIGINT 
 + 
 +==== Input ==== 
 + 
 +HTTP request: GET /health 
 + 
 +OS signal: SIGINT 
 + 
 +==== Output ==== 
 +<code> 
 +OK 
 +Server shutdown completed 
 +</code> 
 + 
 +==== 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 /ɪn flaɪt rɪˈkwɛst/: a request currently being processed+Graceful shutdown /ˈɡreɪsfəl ˈʃʌtdaʊn/: stopping without interrupting work
  
-Signal handling /ˈsɪɡnəl ˈhændlɪŋ/: reacting to OS signals+In-flight request /ɪn flaɪt rɪˈkwɛst/: request being processed
go/interview/live_coding_test.1769822378.txt.gz · Last modified: by phong2018