FastPrepSparse Vector Dot Product from Tuples
Problems/Sparse Vector Dot Product from Tuples

Sparse Vector Dot Product from Tuples

Meta logoMeta● EasyFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report gives the sparse-vector dot product, with follow-ups for dense and sparse forms and for tuples only. It leaves out the size, the tuple format and what to do with repeated indexes. We focus on tuples. Our version is about 88% the same as the reported question.

Two equal-length integer vectors are stored only by their nonzero entries. Each row [index, value] in first or second represents one nonzero value at that zero-based index.

Both tuple arrays use strictly increasing, unique, in-range indices. Compute and return the vectors' dot product as a signed 64-bit integer. Indices missing from a tuple array have value zero.

The vector length length establishes the shared dimension and may be zero.

Function

sparseDotProduct(length: int, first: int[][], second: int[][]) → long

Examples

Example 1

length = 5first = [[0,1],[3,2],[4,3]]second = [[1,3],[3,4]]return = 8

Only index 3 appears in both vectors, contributing 2 * 4 = 8.

Example 2

length = 4first = [[1,-2],[3,5]]second = [[0,7],[1,3],[3,-1]]return = -11

The shared indices contribute -2 * 3 + 5 * -1 = -11.

Example 3

length = 6first = []second = [[2,9]]return = 0

The first vector is all zero, so the dot product is zero.

Constraints

  • 0 <= length <= 10^9.
  • 0 <= first.length, second.length <= 200000.
  • Every tuple contains exactly [index, value].
  • Within each operand, indices are unique, strictly increasing, and satisfy 0 <= index < length.
  • Every stored value is nonzero and lies between -10^9 and 10^9, inclusive.
  • The final dot product fits a signed 64-bit integer.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Two SumMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Find Two-Sum or Three-Sum Index CombinationsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Unique Pairs in a 2D Matrix Summing to TargetAmazon · PHONE SCREEN
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Sparse Vector Dot ProductWhatNot · PHONE SCREENWhatNot interview questions
  • Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
  • Repeated Shortest Word Distance QueriesLinkedIn · PHONE SCREENLinkedIn interview questions
  • Disjoint Target-Sum TripletsAmerican Express · PHONE SCREENAmerican Express interview questions
  • Efficient TeamsExpedia · OAExpedia interview questions

Interview reports that mention this question

  • Meta Software Engineer Onsite Questions: 3 Experiences

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public long sparseDotProduct(int length, int[][] first, int[][] second) {
        // Write your code here.
    }
}
Checking account…