Facebook | Phone | Dot Product of Sparse Vectors
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-03-16Added By Anonymous
Source: Link
Company: Meta (Facebook)
Role: e3, e4
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
I was asked one Data Structure related question in phone interview and I struggled with that.
Problem was: For two vectors VectorA and VectorB, It has integer values like
A = [1,0,0,0,4,0,1]
B= [0,0,0,0,3,0,0]
For Math Operation A*B = A1B1+A2B2+...+AnBn Return Result
For above Example, Answer will be 12 but this can scale upto millions of values.
How would you create Vector Data Structure that holds all non zero values and scales for millions of data ?
Vector {
//Write your Data Structure Here
int product(Vector A, Vector B) {
}
}