Sparse Vector Dot Product with GPU Follow-Up
Updated
Problem statement
Two integer vectors of the same length are represented by their nonzero entries. Each row [index, value] of first or second stores one value at a zero-based coordinate. In each operand, indices are unique, strictly increasing and in range. Every omitted coordinate has value 0.
For this exercise, multiplication means the scalar dot product: sum firstValue(i) * secondValue(i) over coordinates 0 through length - 1. Return that sum as a signed 64-bit integer, using 64-bit arithmetic for products and accumulation. An empty support or a zero-length vector gives 0.
Work directly with the stored entries. The dimension may be much larger than either support, so a dense length-sized array is unnecessary.
GPU follow-up discussion
Discuss how to match nonzero indices in parallel, combine the resulting products safely, and decide whether GPU execution is worthwhile for the workload. This is a discussion follow-up; the submitted function returns the scalar dot product.
Function
sparseDotProduct(length: int, first: int[][], second: int[][]) → longExamples
Example 1
length = 10first = [[0,2],[3,-4],[9,5]]second = [[1,7],[3,6],[9,-2]]return = -34Only indices 3 and 9 occur in both operands. Their contributions are -4 * 6 = -24 and 5 * -2 = -10, giving -34.
Example 2
length = 1000000000first = [[999999999,1000000]]second = [[999999999,1000000]]return = 1000000000000The final valid index contributes 10^6 * 10^6 = 10^12. The large dimension does not require allocating a dense vector.
Example 3
length = 0first = []second = []return = 0There are no coordinates, so the empty sum is 0.
Constraints
0 <= length <= 10^9.0 <= first.length, second.length <= min(256, length).- Every row has exactly two integers:
[index, value]. - Indices within each operand are strictly increasing and satisfy
0 <= index < length. - Every stored value is nonzero and lies in
[-10^6, 10^6]. - Inputs satisfy these rules; duplicate indices and malformed rows are outside the accepted domain.
- Use signed 64-bit products and accumulation; at most
256 * 10^12bounds the magnitude of any partial sum.
More NVIDIA Phone Screen questions
- Network Layer Execution OrderPHONE SCREEN · Seen Nov 2026
- Paged KV Cache AccessPHONE SCREEN · Seen Nov 2026
- Sliding Window Attention over a KV CachePHONE SCREEN · Seen Nov 2026
- Summarize Server Healthcheck LogsPHONE SCREEN · Seen Oct 2026
- Hash Partition OffsetsPHONE SCREEN · Seen Oct 2026
- Filter Paginated Medical RecordsPHONE SCREEN · Seen Oct 2026
- Least Frequently Used CachePHONE SCREEN · Seen Oct 2026
- Parallel String Counts with a Custom Hash TablePHONE SCREEN · Seen Oct 2026
- Simulate a Reference-Counted Smart PointerPHONE SCREEN · Seen Aug 2026
- Streaming Top-K Frequent ElementsPHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Order Powers of Two and ThreeAkuna Capital · PHONE SCREENAkuna Capital interview questions
- Happy NumberSnowflake · PHONE SCREENSnowflake interview questions
- Find All Pythagorean TripletsDell Technologies · PHONE SCREENDell Technologies interview questions
- Sort a Quadratic-Transformed ArrayLinkedIn · PHONE SCREENLinkedIn interview questions
- Add Signed Character ArraysByteDance · PHONE SCREENByteDance interview questions
- Transform L/R Pieces on a Circular BoardGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Fill Missing Points on Line SegmentsDatadog · PHONE SCREENDatadog interview questions
- Count Centaur Friend RequestsMeta · PHONE SCREENMeta interview questions
- Fastest Kilometre SpeedBank of America · PHONE SCREENBank of America interview questions
- Next Palindrome NumberBenchling · PHONE SCREENBenchling interview questions