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

Next revision
Previous revision
go:interview:live_coding_test [2026/01/31 01:18] – created phong2018go:interview:live_coding_test [2026/01/31 01:22] (current) phong2018
Line 1: Line 1:
-1️⃣ Worker Pool with Goroutines and Channels +====== Golang Live Coding Exam (Junior → Middle) ======
-Problem+
  
-Write a program that:+This exam evaluates fundamental Go skills, basic concurrency, and clean coding.
  
-Takes a list of jobs (integers).+Time suggestion: 45–60 minutes
  
-Starts N worker goroutines to process the jobs concurrently.+===== Test 1: Sum of Integers =====
  
-Each job simulates work using time.Sleep and returns jobID * 2.+==== Question ==== 
 +Write a function that receives a list of integers and returns their sum.
  
-Collects and prints results safely (no data races).+==== Input ==== 
 +<code> 
 +[1, 2, 3, 4, 5] 
 +</code>
  
-What this tests+==== Output ==== 
 +<code> 
 +15 
 +</code>
  
-Goroutines and channels+==== Constraints ====
  
-sync.WaitGroup+Do not use external libraries
  
-Concurrency design (worker pool pattern)+Must handle empty slices
  
-Senior extensions+==== Evaluation Criteria ====
  
-Add context.Context to support cancellation+Correct result
  
-Handle job timeouts+Clean and readable code
  
-Graceful shutdown+Proper function signature
  
-📘 Notes+==== Notes ====
  
-Worker pool /ˈwɜːrkər puːl/: a fixed number of workers processing tasks from a queue+Slice /slaɪs/: dynamic array in Go
  
-Data race /ˈdeɪtə reɪs/concurrent access to shared data without synchronization+===== Test 2Word Frequency Counter =====
  
-2️⃣ Rate Limiter (Token Bucket) +==== Question ==== 
-Problem+Given a string, count how many times each word appears.
  
-Implement a rate limiter that:+Words are separated by spaces.
  
-Allows at most X requests per second+==== Input ==== 
 +<code> 
 +"go is fun and go is fast" 
 +</code>
  
-Blocks or rejects requests when the limit is exceeded+==== Output ==== 
 +<code> 
 +go: 2 
 +is: 2 
 +fun: 1 
 +and: 1 
 +fast: 1 
 +</code>
  
-Is safe for concurrent use+==== Constraints ====
  
-What this tests+Case-sensitive
  
-Time-based logic+Use built-in data structures only
  
-Concurrency safety+==== Evaluation Criteria ====
  
-Understanding of rate-limiting algorithms+Correct map usage
  
-Senior extensions+Proper string manipulation
  
-Use time.Ticker+Clean iteration logic
  
-Support burst traffic+==== Notes ====
  
-Make it configurable+Map /mæp/: key-value data structure
  
-📘 Notes+Iteration /ˌɪtəˈreɪʃən/: looping over data
  
-Rate limiter /reɪt ˈlɪmɪtər/controls how frequently an action can happen+===== Test 3Filter Even Numbers =====
  
-Token bucket /ˈtoʊkən ˈbʌkɪt/: algorithm using tokens to allow requests+==== Question ==== 
 +Write a function that returns only even numbers from a list.
  
-3️⃣ Concurrent URL Fetcher with Error Handling +==== Input ==== 
-Problem+<code> 
 +[1, 2, 3, 4, 5, 6] 
 +</code>
  
-Write a function that:+==== Output ==== 
 +<code> 
 +[2, 4, 6] 
 +</code>
  
-Accepts a list of URLs+==== Constraints ====
  
-Fetches them concurrently+Maintain input order
  
-Limits concurrency to N requests at a time+No global variables
  
-Returns results and errors separately+==== Evaluation Criteria ====
  
-What this tests+Correct condition logic
  
-Goroutine orchestration+Proper slice handling
  
-Channel fan-in / fan-out+==== Notes ====
  
-Error handling in concurrent systems+Even number /ˈiːvən ˈnʌmbər/: number divisible by 2
  
-Senior extensions+===== Test 4: Goroutine with Channel =====
  
-Add retry with backoff+==== Question ==== 
 +Create a goroutine that sends numbers from 1 to 3 into a channel. 
 +The main function must receive and print them.
  
-Use context.Context for cancellation+==== Input ==== 
 +<code> 
 +1, 2, 3 
 +</code>
  
-Stop early if too many failures occur+==== Output ==== 
 +<code> 
 +
 +
 +
 +</code>
  
-📘 Notes+==== Constraints ====
  
-Fan-in / Fan-out /fæn ɪn | fæn aʊt/: merging and splitting concurrent flows+Must use one goroutine
  
-Backoff /ˈbækˌɔːf/: waiting longer between retries+Channel must be closed properly
  
-4️⃣ Thread-safe In-Memory Cache with TTL +==== Evaluation Criteria ====
-Problem+
  
-Implement an in-memory cache that:+Correct goroutine usage
  
-Stores key-value pairs+Proper channel closing
  
-Supports TTL (time to live)+No deadlocks
  
-Is safe for concurrent reads and writes+==== Notes ====
  
-What this tests+Goroutine /ˌɡoʊˈruːtiːn/: lightweight concurrent function
  
-sync.Mutex sync.RWMutex+Deadlock /ˈdɛdˌlɒk/: program waits forever
  
-Data consistency+===== Test 5: Simple HTTP Handler =====
  
-Time-based eviction+==== Question ==== 
 +Create an HTTP server that:
  
-Senior extensions+Listens on port 8080
  
-Background cleanup goroutine+Responds "Hello Go" to /hello
  
-LRU eviction strategy+==== Input ==== 
 +<code> 
 +GET /hello 
 +</code>
  
-Metrics (hits/misses)+==== Output ==== 
 +<code> 
 +Hello Go 
 +</code>
  
-📘 Notes+==== Constraints ====
  
-TTL (time to live) /ˌtiː tiː ˈɛl/: how long data stays valid+Use net/http
  
-Eviction /ɪˈvɪkʃən/: removing old data+No third-party libraries
  
-5️⃣ Graceful HTTP Server Shutdown +==== Evaluation Criteria ====
-Problem+
  
 +Correct handler implementation
 +
 +Proper server startup
 +
 +Clean code structure
 +
 +==== Notes ====
 +
 +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 ====
 +
 +Worker pool /ˈwɜːrkər puːl/: group of workers processing tasks
 +
 +Data race /ˈdeɪtə reɪs/: unsafe concurrent memory access
 +
 +===== Test 2: Rate Limiter =====
 +
 +==== Question ====
 +Implement a rate limiter that allows at most 2 requests per second.
 +
 +Each call to Allow() returns:
 +
 +true if the request is allowed
 +
 +false otherwise
 +
 +==== Input ====
 +Call times (milliseconds):
 +
 +<code> 0ms 200ms 400ms 600ms 800ms </code>
 +
 +==== Output ====
 +<code>
 +true
 +true
 +false
 +false
 +false
 +</code>
 +
 +==== Constraints ====
 +
 +Must be safe for concurrent use
 +
 +Must rely on time-based logic
 +
 +Busy-waiting is not allowed
 +
 +==== Evaluation Criteria ====
 +
 +Correct rate limiting
 +
 +Thread-safe implementation
 +
 +Efficient time handling
 +
 +==== Notes ====
 +
 +Rate limiter /reɪt ˈlɪmɪtər/: controls request frequency
 +
 +Busy-waiting /ˈbɪzi ˈweɪtɪŋ/: wasting CPU while waiting
 +
 +===== Test 3: Concurrent URL Fetcher =====
 +
 +==== Question ====
 +Write a function that fetches multiple URLs concurrently, but limits concurrency.
 +
 +==== Input ====
 +
 +URLs:
 +
 +<code>
 +
 +https://example.com/a
 +
 +https://example.com/b
 +
 +https://example.com/c
 +
 +</code>
 +
 +Max concurrency = 2
 +
 +==== Output ====
 +<code>
 +success: https://example.com/a
 +
 +success: https://example.com/b
 +
 +success: https://example.com/c
 +
 +</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 ====
 +
 +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 ====
 +<code>
 +Set("a", 1, ttl=1s)
 +Get("a") -> after 500ms
 +Get("a") -> after 1500ms
 +</code>
 +
 +==== Output ====
 +<code>
 +1
 +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: Create an HTTP server that:
  
-Handles requests normally+Listens on port 8080 
 + 
 +Responds "OK" to /health 
 + 
 +Shuts down gracefully on SIGINT 
 + 
 +==== Input ==== 
 + 
 +HTTP request: GET /health
  
-Listens for OS signals (SIGINT, SIGTERM)+OS signal: SIGINT
  
-Shuts down gracefully without dropping in-flight requests+==== Output ==== 
 +<code> 
 +OK 
 +Server shutdown completed 
 +</code>
  
-What this tests+==== Constraints ====
  
-Real-world Go server knowledge+In-flight requests must complete
  
-Signal handling+Shutdown timeout must be handled
  
-http.Server.Shutdown+No forced exit (os.Exit)
  
-Senior extensions+==== Evaluation Criteria ====
  
-Add request context cancellation+Proper signal handling
  
-Log active connections during shutdown+Correct use of http.Server.Shutdown
  
-Add timeout handling+Clean resource release
  
-📘 Notes+==== Notes ====
  
-Graceful shutdown /ˈɡreɪsfəl ˈʃʌtdaʊn/: stopping without breaking active work+Graceful shutdown /ˈɡreɪsfəl ˈʃʌtdaʊn/: stopping without interrupting work
  
-In-flight request /ɪn flaɪt rɪˈkwɛst/: request currently being processed+In-flight request /ɪn flaɪt rɪˈkwɛst/: request being processed
go/interview/live_coding_test.1769822327.txt.gz · Last modified: by phong2018