Twitter | Phone | Task Assignment
Anonymous User
2390

Had a Twitter phone interview recently.

The question was to implement a simple load balancer.

Interviewer said solution should be clean and not to worry about opitmizing.

I used java and a priorityqueue.

Would like to see others implementation.


Question 1:

Given a list of servers and tasks which all have weights associated with them. You must assign the next task to the server with the lowest current weight.

Example:
list of servers: [x, y, z] - at the start all have 0 tasks

loadbalancer.assign(2) # returns server x (x now has task weighted 2)
loadbalancer.assign(1) # returns server y
loadbalancer.assign(1) # returns server z
loadbalancer.assign(1) # returns server y (y now has task weighted 2)


Question 2:

Expand the above solution to now take in a TTL (long value) for each task. So before you accept and assign the next task, you must remove the expired tasks and assign the new task to the server with the lowest weight.

Comments (6)
No comments yet.