Recruiter contacted over mail, scheduled first interview (at google meet) on a shared virtual pad.
Question:
Given a m*n 2d matrix with some values at each index, return minimum amount of time it will take to reach from start (0, 0) to end (m, n). At each second, all the values gets decreased by 1
We can only travel to a particular index if it's value is 0, otherwise wait for it's adjacent values to come down to 0 and move, Also we can only move either in right direction or downwards.
e.g.
T = 0 sec
1 2 1
3 8 1
T = 1 sec
0 1 0
2 7 0
T = 2 sec
0 0 0
1 6 0
now the path exists (marked in bold) so return the time which is 3
Brute Force Approach:
at every second, check if path exists between start and end then return the time otherwise keep on subtracting form each cell index
complexity = O(mnt) given t can be max of all the cells, and it might be order of m * n so overall O(m * n * m * n)
Optimisation approach:
Using DP - started from bottom right corner and moved up, and at every stage, minimised the maximum values of all adjacent cells, and updated current cell with that, and returned the top most element.
Also explained maybe kruskal or dijkstra algorithm can work, but due to 45 minutes time limitation, only wrote up the DP approach
Can there be any other approach optimising further?
Update:
Recruiter told to conduct a phone screen as for this question I didn't covered up edge cases.
After 2 weeks phone screen was conducted (Someone from Zurich called me)
Phone Screen: Given number of leaf nodes, return all the possible complete binary trees out of it.
Explained the Algorithm well, and coded up (but forgot to do nodes = 2 * leaf - 1)
After 1 week got rejection mail.
[Hoping to study more and apply again in 1 year]
Edit: I asked recruiter about feedback, she haven't replied yet, is this normal or should they reply?