GO TO A SECTION

↑ ↓ to navigate · Enter to openExplore all sections →
FDEInterviews logo
← 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.

20 answers per topic instead of 10, plus saved progress and bookmarks · no cardor unlock all 559 remaining answers · ₹2,000 / $25

Every answer, concept and course, every paper breakdown, all published video lessons, hands-on FDE Lab missions, Premium PDF guides and companion files, the full practice-test bank and work-sample downloads. Referral Premium excludes guide PDFs and their companion files.

6 months · One payment · No auto-renewal

Study alongside free video lessons.

Keep practising

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.