FastPrepSparse Valid Conv2D From Scratch
Problems/Sparse Valid Conv2D From Scratch

Sparse Valid Conv2D From Scratch

NVIDIA logoNVIDIA● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA online assessment for a full-time role. The report asks for Conv2D from scratch and a loop optimization. It leaves out the tensor dimensions and the operator conventions. This version is a single-channel valid convolution.

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

Implement two-dimensional valid cross-correlation from scratch over one integer image and one integer kernel. At each output position [row][col], sum image[row + dr][col + dc] * kernel[dr][dc] over every kernel cell. Return all valid output positions in a rectangular matrix.

Use the common ML convention: do not reverse the kernel. There is one channel, unit stride, no padding and no dilation. The output has imageRows - kernelRows + 1 rows and imageCols - kernelCols + 1 columns. An optimized implementation can precompute nonzero kernel taps and avoid copying every image patch.

Function

conv2D(image: int[][], kernel: int[][]) → int[][]

Examples

Example 1

image = [[1,2,3],[4,5,6],[7,8,9]]kernel = [[1,0],[0,-1]]return = [[-4,-4],[-4,-4]]
image
012012314562789
→
return
010-4-41-4-4

The asymmetric diagonal weights distinguish kernel orientation.

Example 2

image = [[2,-1],[-3,4]]kernel = [[2]]return = [[4,-2],[-6,8]]
image
0102-11-34
→
return
0104-21-68
Moved or new

A one-cell filter scales every pixel, preserving the matrix shape.

Example 3

image = [[1,2,3],[4,5,6]]kernel = [[0,0,0],[0,0,0]]return = [[0]]
image
01201231456
→
return
000

A full-size all-zero filter produces one zero.

Constraints

  • The image is rectangular, with 1 to 30 rows and 1 to 30 columns.
  • The rectangular kernel has at least one row and column, and fits within the image in both dimensions.
  • Each image and kernel entry is an integer in [-100,100].
  • Every result fits in a signed 32-bit integer.

More NVIDIA Online Assessment questions

  • Query a Header-Encoded MatrixOA · Seen Oct 2026
  • Maximum ScoreOA · Seen Oct 2026
  • Address on Same PageOA · Seen Oct 2026
  • Minimize Task Resource ConsumptionOA · Seen Oct 2026
  • Minimum Project Bid CostOA · Seen Oct 2026
  • Count Ideal Numbers in a RangeOA · Seen Oct 2026
  • Generate Bit MaskOA · Seen Oct 2026
  • Reconstruct an Array from Prefix XOROA · Seen Oct 2026
  • Sum of Subarray MinimumsOA · Seen Oct 2026
  • Unique Integers That Sum to ZeroOA · Seen Oct 2026

Similar questions at other companies

  • Maximum Diamond SumHudson River Trading · OAHudson River Trading interview questions
  • Robot Navigation Around LasersRoblox · OARoblox interview questions
  • Apply a Reversi MoveAmazon · OA
  • Flip, Invert, and Smooth a Binary ImageAbridge · OAAbridge interview questions
  • First Completed Mingo LineEpic · OAEpic interview questions
  • Rotate a Square Matrix ClockwiseVisa · OAVisa interview questions
  • Sort Concentric Matrix Borders ClockwiseByteDance · OAByteDance interview questions
  • Apply Matrix OperationsCapital One · OACapital One interview questions
  • Rotate the Box and Drop the StonesZipRecruiter · OAZipRecruiter interview questions
  • 2048 Move SimulatorBenchling · OABenchling interview questions

Interview reports that mention this question

  • NVIDIA OA: What It Tests (2026)

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA DevOps, QA and Infra Intern Interviews: 12 Experiences
  • NVIDIA Ignite Internship OA Experience
  • NVIDIA Software Intern Interview Questions: 9 Experiences
  • NVIDIA Ignite SWE Intern OA Questions: 6 Experiences
All NVIDIA interview questionsSee NVIDIA hiring insights
Saved
class Solution {
    public int[][] conv2D(int[][] image, int[][] kernel) {
        // Compute each valid output position.
    }
}
Checking account…