Rubrik | G6 | Bangalore | 2025 | Reject
1630
Apr 26, 2025

Question 1. There are some tasks which depend on each other . example b depends on completion of a. c depends on completion of a and b.
There is a function you are provided which you can use to get this information . getDependentTasks(a) -> returns b , getDependentTasks(a,b) -> returns c .
Implement a job scheduler with multiple threads such that all parent tasks are completed before child task . ie . a should complete before b . then b should complete then c.
Initial input to the function is blank which returns a so This is the starting point .
Each task has a function called doWork() which you need to run .
keep in mind that if any of the task throws an exception you have to immediately stop execution of all tasks and return .
You are not allowed to use in built java libraries . create blocking queues of your own , thread pools , executors everything has to be created on your own using locks .

Approach . Start with task A . put incomplete tasks in a blocking Queue . Worker threads will pick up jobs one by one and try to run it . put completed tasks in a list .
pass this list to the getDependenctTasks() function everytime to get what are the next functions you can run . get those and put them on the queue .
Each worker thread polls from the queue and runs the job . if the job run fails it marks a shared variable as true . like isShutdown = true .
We use this variable to check if we can keep running the jobs or stop it . This variable can be set in the catch part .

Question 2. You are given 2 functions . pread(buffer,number of characters to be read,file name) and pwrite(buffer,number of characters to write,file name) . You have to use these functions to write code which will read from a file and write it to another file . How would you do this parallely using multiple threads .

Rejected due to average feedback in round 2

Comments (2)