FastPrepSparse Vector Dot Product
Problems/Sparse Vector Dot Product

Sparse Vector Dot Product

WhatNot logoWhatNot● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a phone screen for an experienced engineer at Whatnot in mid 2026, as the first of two coding questions. The task was to multiply two vectors (the dot product), and the follow-up asked what changes when almost every entry of both vectors is zero.

The report does not say how the vectors are passed in. Here, both are plain integer arrays of the same length with at most 1000 nonzero entries each, and the answer is a 64-bit integer.

Our version is about 85% the same as the reported question.

You are given two integer arrays nums1 and nums2 of the same length n. Each array is a vector, and many of its entries may be 0.

Return their dot product: the sum of nums1[i] * nums2[i] over every index i from 0 to n - 1.

Function

dotProduct(nums1: int[], nums2: int[]) → long

Examples

Example 1

nums1 = [0,3,0,0,2]nums2 = [5,4,0,1,6]return = 24

Only indexes 1 and 4 are nonzero in both arrays. The sum is 3 * 4 + 2 * 6 = 24. Index 0 and index 3 add nothing, because one side is 0.

Example 2

nums1 = [7,0,0]nums2 = [0,0,9]return = 0

The two arrays have no nonzero entry at the same index, so every product is 0.

Example 3

nums1 = [100000,-100000,100000]nums2 = [100000,-100000,100000]return = 30000000000

Each product is 10^10, and the sum is 3 * 10^10. This is larger than a 32-bit integer can hold.

Example 4

nums1 = [0,-4,0,5]nums2 = [0,3,0,2]return = -2

The products at indexes 1 and 3 are -12 and 10, so the sum is -2.

Constraints

  • 1 <= n <= 10^5
  • nums1.length == nums2.length == n
  • -10^5 <= nums1[i], nums2[i] <= 10^5
  • Each array has at most 1000 nonzero entries.

More WhatNot Phone Screen questions

  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Nov 2026
  • Merge Sorted Squares of Two ArraysPHONE SCREEN · Seen Nov 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Knight Dialer SequencesPHONE SCREEN · Seen Oct 2026
  • Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
  • Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
  • Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
  • Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
  • Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026

Similar questions at other companies

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

WhatNot interview experiences

  • Whatnot SWE New Grad Second Technical Interview: 8 Experiences
  • Whatnot interviews · October 2026
  • Whatnot Experienced SWE Phone Screen Questions: 2 Experiences
  • Whatnot SWE Interview Questions: 6 Experiences
All WhatNot interview questionsSee WhatNot hiring insights
Saved
class Solution {
    public long dotProduct(int[] nums1, int[] nums2) {
        // write your code here
    }
}
Checking account…