FastPrepBatched Strided Convolution
Problems/Batched Strided Convolution

Batched Strided Convolution

Tesla logoTesla● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tesla Autopilot technical phone screen as a 3D convolution task. The report gives the batch and channel shapes and the stride. It leaves out the padding and how numbers are handled. Our version is about 80% the same as the reported question.

Implement a batched, multi-channel two-dimensional convolution using direct loops.

The logical input tensor has shape [batchSize][channels][height][width]. In this problem, input flattens the first two dimensions into shape [batchSize * channels][height][width]; plane b * channels + c is channel c of batch item b.

Each row kernels[f] stores output filter f in channel-major order. Its entry for input channel c, kernel row kr, and kernel column kc is at index c * kernelHeight * kernelWidth + kr * kernelWidth + kc.

Use the given positive stride and no padding. Slide the kernel the way neural networks do (cross-correlation): do not flip the kernel, add a bias, or apply an activation.

The output height is floor((height - kernelHeight) / stride) + 1, and the output width is found the same way from the width. Return the output with batch and output-channel dimensions flattened in batch-major order: plane b * outputChannels + f stores filter f for batch item b.

Function

convolveBatched(input: int[][][], batchSize: int, channels: int, kernels: int[][], kernelHeight: int, kernelWidth: int, stride: int) → int[][][]

Examples

Example 1

input = [[[1,2,3],[4,5,6],[7,8,9]]]batchSize = 1channels = 1kernels = [[1,0,0,-1]]kernelHeight = 2kernelWidth = 2stride = 1return = [[[-4,-4],[-4,-4]]]

There is one batch item and one filter. At the top-left position, the sum is 1 * 1 + 2 * 0 + 4 * 0 + 5 * (-1) = -4.

Example 2

input = [[[1,2,3],[4,5,6],[7,8,9]],[[9,8,7],[6,5,4],[3,2,1]]]batchSize = 2channels = 1kernels = [[1,1,1,1]]kernelHeight = 2kernelWidth = 2stride = 2return = [[[12]],[[28]]]

The stride leaves one valid window per batch item. Their sums are 12 and 28.

Example 3

input = [[[1,2,3],[4,5,6]],[[10,20,30],[40,50,60]]]batchSize = 1channels = 2kernels = [[1,1,0,0],[0,0,1,-1]]kernelHeight = 1kernelWidth = 2stride = 1return = [[[3,5],[9,11]],[[-10,-10],[-10,-10]]]

The first filter adds adjacent values from channel 0. The second subtracts adjacent values in channel 1.

Constraints

  • 1 <= batchSize <= 4.
  • 1 <= channels <= 8.
  • input.length == batchSize * channels.
  • 1 <= height, width <= 20.
  • 1 <= kernels.length <= 8.
  • 1 <= kernelHeight <= height and 1 <= kernelWidth <= width.
  • Every row of kernels has length channels * kernelHeight * kernelWidth.
  • 1 <= stride <= max(height, width).
  • All input and kernel values are between -100 and 100, inclusive.
  • Every output value fits in a signed 32-bit integer.

More Tesla Phone Screen questions

  • Flatten a Branched List into a Doubly Linked ListPHONE SCREEN · Seen Sep 2026
  • Reduce-Based Map and Filter PipelinePHONE SCREEN · Seen Sep 2026
  • Resilient Fake API ClientPHONE SCREEN · Seen Sep 2026
  • Merge JSON Array FieldsPHONE SCREEN · Seen Aug 2026
  • KV Store with RollbackPHONE SCREEN · Seen Apr 2026
  • Multi-Channel Valid ConvolutionPHONE SCREEN · Seen Oct 2024
  • Course Schedule FeasibilityPHONE SCREEN · Seen Aug 2024
  • Average of a Fixed-Size ArrayPHONE SCREEN · Seen Jun 2024
  • Swap Even and Odd BitsPHONE SCREEN · Seen Mar 2023
  • Find the Intersection Node of Two Linked ListsPHONE SCREEN · Seen Oct 2022

Similar questions at other companies

  • Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
  • Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
  • Incremental Hard Attention with a KV CacheOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Longest Consecutive Same-Color LineGoogle · PHONE SCREENGoogle interview questions
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
  • Diagonal TraverseHive · PHONE SCREENHive interview questions
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREENNVIDIA interview questions
  • Read a Matrix in Spiral OrderAdobe · PHONE SCREENAdobe interview questions

Tesla interview experiences

  • Tesla Experienced Infrastructure SWE Interviews: 1 Experience
  • Tesla Older SWE Intern Reports: 14 Experiences (Part 4 of 4)
  • Tesla Embedded and SRE Intern Loops: 15 Experiences (Part 3 of 4)
  • Tesla SWE and Data Intern Rounds: 10 Experiences (Part 2 of 4)
  • Tesla Intern Python Interview Prep Guide
  • 2017–2026 Tesla Intern OA / Interviews: 83 Experiences (Part 2 :)
All Tesla interview questionsSee Tesla hiring insights
Saved
class Solution {
    public int[][][] convolveBatched(int[][][] input, int batchSize, int channels, int[][] kernels, int kernelHeight, int kernelWidth, int stride) {
      // write your code here
    }
}
Checking account…