FDEInterviews logoFDE/Interviews
Coding & DSA / 71
mediumMetaGoogle

Compute the dot product of two sparse vectors.

The whole question is the representation: store only the nonzeros as index→value, then either two-pointer over sorted indices or hash-join. The follow-up that decides the design is what happens when one vector is dense.

Updated Aug 2026 · Grounded in real Forward Deployed Engineer interview loops and written to a senior-engineer editorial bar.

The whole question is the representation: store only the nonzeros as index→value, then either two-pointer over sorted indices or hash-join. The follow-up that decides the design is what happens when one vector is dense.

Unlock the other 466 answers · ₹2,000 / $25Your progress and mastery stay saved · 6 months · one payment · no auto-renew
UP NEXT ON YOUR JOURNEY
FEDITOR'S NOTE

This is a representation question wearing a math question's clothes. Interviewers want you to reject the dense array immediately (the vectors are 'sparse' for a reason), pick index->value pairs, and then defend two-pointer vs hashmap. The two-pointer answer is O(n+m) with no hashing overhead when both are sorted; the hashmap shines on the real follow-up, when one vector is huge and dense so you should iterate the small one and look up the big one.

DISCUSSION · 0

No comments yet — be the first to share your approach.