Convolution Output Dimensions
Updated
Problem statement
Calculate the spatial output dimensions of a two-dimensional convolution layer. The integer arrays inputShape, kernelSize, stride, padding, and dilation each contain two entries in [height, width] order.
For each axis:
padding[axis]positions are added on each side of the input axis.- A kernel has
kernelSize[axis]taps. The distance from one tap to the next isdilation[axis], so tapjlies atanchor + j * dilation[axis]in the padded axis. - The first anchor is
0in the padded axis, and subsequent anchors advance bystride[axis]. - Count a placement only when every kernel tap lies inside the padded axis. Discard an incomplete trailing placement.
Return [outputHeight, outputWidth]. Batch size, channel counts, and tensor values are outside this exercise. Each input is valid and allows at least one complete placement on both axes.
Function
convolutionOutputShape(inputShape: int[], kernelSize: int[], stride: int[], padding: int[], dilation: int[]) → int[]Examples
Example 1
inputShape = [8,9]kernelSize = [3,3]stride = [2,2]padding = [1,1]dilation = [1,1]return = [4,5]The padded height is 10. Valid height anchors are 0, 2, 4, 6; anchor 8 would place the final tap at 10, outside the padded axis. The padded width is 11, with valid anchors 0, 2, 4, 6, 8.
Example 2
inputShape = [7,7]kernelSize = [3,3]stride = [1,1]padding = [0,0]dilation = [2,2]return = [3,3]Each kernel uses offsets 0, 2, 4, spanning 5 positions. Anchors 0, 1, 2 fit on each length-7 axis.
Example 3
inputShape = [3,5]kernelSize = [3,5]stride = [5,7]padding = [0,0]dilation = [1,1]return = [1,1]The kernel exactly covers the input. Anchor 0 fits on each axis, and the next stride would extend past the edge. A stride larger than the axis still allows the initial placement.
Constraints
- All five input arrays have length
2. 1 <= inputShape[axis] <= 1000.1 <= kernelSize[axis], stride[axis], dilation[axis] <= 100.0 <= padding[axis] <= 1000.- For both axes,
(kernelSize[axis] - 1) * dilation[axis] + 1 <= inputShape[axis] + 2 * padding[axis].
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
- Parking Fee CalculatorBreeze · PHONE SCREEN
- Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions
- Subtract Two Large Number StringsStackAdapt · PHONE SCREENStackAdapt interview questions
- Fair Coin from a Biased CoinAnthropic · PHONE SCREENAnthropic interview questions
- Three Points in a Semicircle: Monte Carlo EstimateSquarepoint Capital · PHONE SCREENSquarepoint Capital interview questions
- Apply Affine Array TransformationsByteDance · PHONE SCREENByteDance interview questions
- Exponential Backoff DelaysWonderful · PHONE SCREEN
- Add Two Integers Given as StringsJane Street · PHONE SCREENJane Street interview questions
- Fizz and Buzz Words From 1 to nDocuSign · PHONE SCREENDocuSign interview questions
- Recover Document Hierarchy from IndentationReducto · PHONE SCREEN