Sparse Valid One-Dimensional Convolution
Updated
Problem statement
Implement one-dimensional valid cross-correlation over integer arrays signal and kernel. At output position start, multiply signal[start + tap] by kernel[tap] for every tap and sum the products. Return the output for each start from zero through signal.length - kernel.length, in increasing start order.
This exercise uses the common ML convention: do not reverse the kernel. Use one channel, unit stride, no padding and no dilation. An optimized implementation can precompute nonzero taps and avoid copying each input window.
Function
convolve1D(signal: int[], kernel: int[]) → int[]Examples
Example 1
signal = [2,1,3,4]kernel = [1,0,-1]return = [-1,-3]Asymmetric taps take the first value minus the value two positions later.
Example 2
signal = [3,-2,5]kernel = [2]return = [6,-4,10]A one-tap kernel scales each signal value.
Example 3
signal = [1,2,3]kernel = [0,0,0]return = [0]An all-zero kernel yields one zero for this full-width window.
Constraints
1 <= kernel.length <= signal.length <= 1000.- Each signal and kernel entry is an integer in
[-1000,1000]. - Every resulting sum fits in a signed 32-bit integer.
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Random Bingo Card GeneratorUber · ONSITE INTERVIEWUber interview questions
- Spiral MatrixAthenahealth · ONSITE INTERVIEW
- Spiral MatrixNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Stochastic Gradient Descent with MomentumMeta · ONSITE INTERVIEWMeta interview questions
- Game of Life: In-Place Next GenerationGoogle · ONSITE INTERVIEWGoogle interview questions
- Candy Crush Board Until StableBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Game of Life Next GenerationTemporal · ONSITE INTERVIEWTemporal interview questions
- Minesweeper Board UpdateClay · ONSITE INTERVIEW
- Minesweeper Board UpdateAirbyte · ONSITE INTERVIEW
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
- Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
- Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
- Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)