Online Assessment (60 minutes) [Jan'2025]
Online test was heavily proctored and was conducted on the Hackerank platform. Sreensharing and webcam permission were asked. There were two coding questions both were Medium to Hard difficulty.
Question 1: A server network is represented as a tree of g_nodes servers indexed from 1 to g_nodes and g_nodes - 1 edges where the ith edges connect the servers g_from[i] and g_to[i]. The transfer time between any two connected servers is 1 unit.
Given the graph g, find the maximum time taken to transfer the data between any two servers in the system.
Example
Suppose g_nodes = 3, g_from = [1, 2], g_to = [2, 3]
The maximum time required to transfer data from 1 to 3 that takes 2 units of time. Hence, the answer is 2.
- Sample Case 0:
- Sample Input:
5 4
1 5
1 3
1 2
5 4
g_nodes = 5, g_nodes - 1 = 4
g_from[] = [1, 1, 1, 5], g_to[] = [5, 3, 2, 4]
Sample Output: 3
- Sample Input:
- Sample Case 1:
- Sample Input:
7
6
4 2
4 7
2 5
1 6
2 3
g_nodes = 7, g_nodes = 1 - 6
g_from[] = [4, 4, 2, 1, 2], g_to[] = [2, 7, 5, 6, 3]
Sample Output: 4
- Sample Input:
Question 2: There are n processes to be executed, and the iᵗʰ process has a size of processSize[i], where 1 ≤ i ≤ n. Also, there are m processors of different size capacity. The capacity of the iᵗʰ processor is capacity[i] ( 1 ≤ i ≤ m ). A processor can process a task of size less than or equal to its capacity in 1 second, but it cannot execute processes whose size is greater than its capacity.
A processor can execute multiple processes one after the other, but needs to pause for 1 second after completing its current one. Multiple processors can work on different processes simultaneously.
Find the minimum time to execute all the processes or return -1 if there is no way to execute all the processes.
Example
It is given that n = 3, processSize = [2, 5, 3], m = 3 and capacity = [6, 2, 4]
The optimal way to assign processes is to give:
- The first processor the second process
- The second processor the first process
- The third processor the third process
All of them complete their processes in 1 second. Therefore, the minimum time required is 1 second.
- Sample Case 0:
- Sample Input:
STDIN FUNCTION
5 processSize[] size n = 5
1 processSize = [1, 2, 3, 4, 6]
3 capacity[] size n = 3
4 capacity = [4, 1, 4]
6
Sample Output: 3
Explanation: Assign the second and third process to the first processor. It completes the first process in 1 second, then pauses for another second before completing the third process in 1 second
- Sample Input:
- Sample Case 1:
- Sample Input:
STDIN FUNCTION
3 processSize[] size n = 3
2 processSize = [2, 5, 8]
5 capacity[] size n = 3
8 capacity = [6, 7, 4]
3
6
7
4
Sample Output: -1
Explanation: No processor has the required capacity to process the third process (size = 8), so there is no way to process them all.
- Sample Input:


