Facebook/Meta E4 SWE | Phone Screening | 2 Coding Questions
Anonymous User
2069

Interview Duration - 45 mins
Time available for each problem - 20 mins
Execution is disabled => No way to run the code and no requirement to run any test cases

Problem #1

Given a matrix of integers print out its values along the diagonals that move in the top right to bottom left direction. Each diagonal goes down and to the left as shown in the example. There should be newlines between each diagonal.
Example:
Input -
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
Output -
1
2 5
3 6 9
4 7 10
8 11
12

Problem #2

Given 2 one-dimensional arrays a and b of same length N write a function to calculate
a1*b1 + a2*b2 + a3*b3 + ..... + aN*bN

Follow up question: say a = [1, 0, 3, 0, 5, 0, 7, 0, 9, 0] and b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] wherein one or both the arrays has some of the elements as zeros then could you provide a better solution to store the array elements? [Since zeros are of no use in computing the required sum I proposed array elements can be stored in a dict with (key,value) as (index,element) and updated the initial code solution such that I was iterating over all the pairs of both dicts corresponding to a and b]

Another follow up question: Let us say any one of these arrays has most of the elements zeros then can you improve the time complexity of the solution? [As I was running out of time and the interviewer was fine too to just provide the logic verbally, I said instead of iterating over all the pairs of both dicts we can just iterate over the pairs of the dict which has fewer pairs]

Find more here - https://leetcode.com/problems/dot-product-of-two-sparse-vectors/

Comments (9)