Saturday, June 27, 2020

Interviewing.io: Coding Interview | Software Engineer @ Facebook

Here is the link.

Two algorithms:

First one is tree algorithm - first 16 minutes

Binary tree - find average for each level
The idea is to use BFS, using queue, get count of level nodes, and sum of level node's values.

Second one is to find minimum distance to gates.

Given a 2d matrix nxm size
unfilled calls: 0
walls: -1
gates: -2

Run BFS algorithm, put all -2 on the queue, and then run BFS algorithm to mark nodes with 0 using minimum distance.

The interviewee took DFS approach which is not optimal. Last 5 minutes interviewer gave him the hint to put all -2 on the queue, and then visit all neighbors, put all those neighbors in the queue, level by level order traversal.








No comments:

Post a Comment