Uber SSE Phone Screen NY

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2022-06-01Added By Anonymous
Source: Link

Company: Uber

Role: Senior Software Engineer / Staff Software Engineer

Interview Stage: Phone Screen

Location: NY


Original Post Content:


'''

'''


Implement a Job class that has an Exec function and a name identifier.

The Exec() function should sleep for x ms

class Job {

Exec()

}


// example instance of this class

jA = new Job("a", 10)

jB = new Job("b", 50)

jA.Exec() // generating a payment

jB.Exec()


// OUTPUT

starting job a - sleep for: 10ms

finished job a

starting job b - sleep for: 50ms

finished job b


Implement a Runner class that can be initialized with N workers. each worker can run Job::Exec() in parallel

Jobs can be Submitted to the Runner via ::Submit function.


The ::Submit function is NON-BLOCKING, meaning I can call the submit function with new jobs as many times as I want,

and once I have finished submitting, the program moves on. However, jobs should be executed in the order that they were submitted.


class Runner {

Submit(j Job)

// Can have more functions if you want

}


// EXAMPLE - 3 Workers //

jobs = [Job("a", 10), // will sleep for 10 ms when ::Exec() is called

Job("b", 20),

Job("c", 30),

Job("d", 10),

Job("e", 20)]


runner = Runner(3) // a runner with 3 workers

for i = 0; i<jobs.Length; i++ {

runner.Submit(jobs[i]) //non blocking!!

}


// OUTPUT

starting job a - sleep for: 10ms

starting job c - sleep for: 30ms

starting job b - sleep for: 20ms

finsihed job a

starting job d - sleep for: 10ms

finsihed job d

starting job e - sleep for: 20ms

finsihed job b

finsihed job c

finsihed job e

'''

Comments