Interviewer was very friendly and made me very confortable on 45 minutes interview. I felt a bit of difficulty because of the interviewer accent. I am applying for E5 Software Engineer position.
1. Squared sorted list
Given a sorted list, return the sorted version of the squared elements.
input = [-5, -3, 0, 1, 2 ,4, 6]
output= [0, 1, 4, 9, 16, 25, 36]First I proposed create a output variable that would contain all the squared elements from the original array. Than I could sort it.
He asked me the complexity for that and I said O(nlogn) if we use HeapSort. He ask for a more efficient solution.
I proposed a solution using O(n) using pointers i,j that moves to positive and negative numbers.
Implemented the code - all good.
Overview question 1:
Did the implementation pretty well but I had a bit of problem to understand the question at first. He gave me some tips.
2. Compress vectors
a = <1,1,1,1,1,3,3,3,3,3,6,6,6,6,6,2,2,2,2,2>How could you implement a way to optimize the memory usage for that?
I proposed organize the array like this:
a = [ [1,5], [3,5], [6,5],[2,5]]He said ok, and move for one more question.
What if we add a new vector b and you need to calculate the dot product a*b?
b = <1,1,1,1,1,2,2,2,2,2,2,2,5,5,5,5,5>At this point I did not understand so well what this product would work. He gave me more examples about how the product would work but I did not had time to implement the code, just could explain the idea.
Overview question 2:
Spent so much time in the understanding of the question. It was not so clear to me.
General overview:
I had some problems to clearly understand the input and expected output. I got stuck twice in that part. In general I communicate pretty well and could explain him my ideas clearly. The code also was clean and consise.
Update: Rejected