1D Convolution (Valid)
Description
Given a 1D signal and a 1D kernel, return the valid cross-correlation (the operation deep-learning libraries call convolution): slide the kernel over the signal without padding and, at each position, return the sum of element-wise products. The output length is signal length minus kernel length plus 1.
Examples
[1,2,3,4], [1,0][1,2,3]The kernel slides across the signal one step at a time, and each output is the dot product of the kernel with the window it currently covers.
[1,2,3], [1,1][3,5]The kernel slides across the signal one step at a time, and each output is the dot product of the kernel with the window it currently covers.
[1,2,3,4,5], [1,2,1][8,12,16]The kernel slides across the signal one step at a time, and each output is the dot product of the kernel with the window it currently covers.
Constraints
- •
1 ≤ kernel length ≤ signal length ≤ 10⁴
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.