FastPrepTensor Shapes Through a Neural Network
Problems/Tensor Shapes Through a Neural Network

Tensor Shapes Through a Neural Network

NVIDIA logoNVIDIA● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an NVIDIA phone screen for a full-time role. The report asks for every layer's input and output tensor shape but leaves out the model and the conventions. Here we use a sequential convolutional model, and state the layout, the layer rules, and which inputs are valid.

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

You are given the shape of an input tensor and a list of neural-network layers. Return the tensor shape before the first layer and after every layer. You only work out sizes. No tensor values or weights are given.

The layers run one after another. The starting shape initialShape is [N, C, H, W]: the batch size, the number of channels, the height and the width. The arrays layerTypes and layerParameters describe the same layers: entry i of each array is layer i, and the layers run in array order.

Layer rules

  • CONV takes the parameters [outChannels, kernelHeight, kernelWidth, strideHeight, strideWidth, paddingHeight, paddingWidth]. It turns [N,C,H,W] into [N,outChannels,outputHeight,outputWidth]. Each axis gets the same padding on both sides. The dilation is 1.
  • POOL takes the parameters [kernelHeight, kernelWidth, strideHeight, strideWidth]. It turns a four-dimensional shape into another four-dimensional shape and keeps N and C the same. Its padding is 0 and its dilation is 1.
  • CONV and POOL are the spatial layers. For both, the output length of an axis is 1 + floor((inputLength + 2 * padding - kernelLength) / stride). Only full windows count. A partial window at the end is dropped.
  • FLATTEN takes no parameters, []. It turns [N,C,H,W] into [N,C * H * W].
  • LINEAR takes the parameters [outFeatures]. It turns [N,features] into [N,outFeatures].

Every input is a valid model. It has zero or more spatial layers, then maybe one FLATTEN, then zero or more LINEAR layers. The model may stop after any of these parts. You do not need to handle invalid shapes.

If there are L layers, return L + 1 rows. Row 0 is initialShape, and row i + 1 is the output of layer i. So row i is the input of layer i, and row i + 1 is its output. With no layers, return just the initial shape. A row has four numbers before flattening and two numbers after it.

Function

tensorShapeTrace(initialShape: int[], layerTypes: String[], layerParameters: int[][]) → int[][]

Examples

Example 1

initialShape = [2,3,8,9]layerTypes = ["CONV","POOL","FLATTEN","LINEAR"]layerParameters = [[4,3,3,2,2,1,1],[2,2,2,2],[],[5]]return = [[2,3,8,9],[2,4,4,5],[2,4,2,2],[2,16],[2,5]]

The convolution produces 4 channels and spatial dimensions 4 by 5. Pooling keeps the batch and channels, producing 2 by 2. Flattening gives 4 * 2 * 2 = 16 features per sample, and the linear layer produces 5 features.

Example 2

initialShape = [1,2,10,13]layerTypes = ["CONV","CONV"]layerParameters = [[5,3,4,3,4,0,0],[2,2,1,2,2,1,0]]return = [[1,2,10,13],[1,5,3,3],[1,2,2,2]]

The first layer uses complete windows, so the height and width are both 3. The second layer receives that output, uses height padding 1 and width padding 0, and produces shape [1,2,2,2].

Example 3

initialShape = [3,2,2,4]layerTypes = ["FLATTEN","LINEAR","LINEAR"]layerParameters = [[],[7],[2]]return = [[3,2,2,4],[3,16],[3,7],[3,2]]

Flattening combines only the channel and spatial axes: 2 * 2 * 4 = 16. Each linear layer replaces the feature count while preserving batch size 3. The output includes the initial shape and all three layer outputs.

Constraints

  • initialShape.length = 4, and 0 <= layerTypes.length = layerParameters.length <= 80.
  • 1 <= N, C, outChannels <= 64.
  • Every spatial input and output dimension is between 1 and 128.
  • Every kernel size and stride is between 1 and 128; convolution padding is between 0 and 64.
  • Each kernel fits within the current padded input axis, so both spatial outputs are positive.
  • 1 <= outFeatures <= 1048576. Flattening produces at most 64 * 128 * 128 = 1048576 features.
  • Layer names, parameter counts and layer ordering follow the stated rules.

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

NVIDIA interview experiences

  • NVIDIA Full-Time SWE Onsite Scheduling: 1 Experience
  • NVIDIA OA: What It Tests (2026)
  • 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[][] tensorShapeTrace(int[] initialShape, String[] layerTypes, int[][] layerParameters) {
        // Return the initial shape and the output shape after every layer.
    }
}
Checking account…