FastPrepMulti-Channel Valid Convolution
Problems/Multi-Channel Valid Convolution

Multi-Channel Valid Convolution

Tesla logoTesla● MediumNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Tesla Machine Learning Engineer technical interview. The new grad candidate says the process was moved to a senior-level loop. The report keeps the multi-channel tensor shapes but not the final padding and stride choices. Our version is about 80% the same as the reported question.

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

The input tensor input has shape [channels][height][width]. There are filters convolution kernels. Each kernels[f] holds filter f as one flat row, with one channel after another. The value for channel c, kernel row r, and kernel column k is at index c * kernelHeight * kernelWidth + r * kernelWidth + k.

Use stride 1, no padding, and the cross-correlation convention used by neural-network layers: do not reverse the kernel. Do not add a bias or apply an activation function.

Return a tensor of shape [filters][height - kernelHeight + 1][width - kernelWidth + 1]. Each output value is the sum, over every input channel and kernel position, of the corresponding input value multiplied by its kernel value.

Function

convolveValid(input: int[][][], kernels: int[][], kernelHeight: int, kernelWidth: int) → int[][][]

Examples

Example 1

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

There is one channel and one 2 x 2 filter. At the top-left position, the sum is 1 * 1 + 2 * 0 + 4 * 0 + 5 * (-1) = -4. The same difference appears at every valid position.

Example 2

input = [[[1,2],[3,4]],[[5,6],[7,8]]]kernels = [[1,0,0,1,0,1,1,0]]kernelHeight = 2kernelWidth = 2return = [[[18]]]

The first channel contributes 1 + 4 = 5, and the second contributes 6 + 7 = 13, for a total of 18.

Example 3

input = [[[1,2,3],[4,5,6]]]kernels = [[1,1],[1,-1]]kernelHeight = 1kernelWidth = 2return = [[[3,5],[9,11]],[[-1,-1],[-1,-1]]]

The first filter adds adjacent values. The second subtracts the second value in each window from the first.

Constraints

  • 1 <= channels <= 8.
  • 1 <= height, width <= 20.
  • 1 <= filters <= 8.
  • 1 <= kernelHeight <= height and 1 <= kernelWidth <= width.
  • kernels.length == filters.
  • Every row of kernels has length channels * kernelHeight * kernelWidth.
  • 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
  • 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
  • Priority, Expiration, and LRU EvictionPHONE SCREEN · Seen Mar 2021

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
  • Game of Life on a Finite and an Infinite BoardCitadel · PHONE SCREENCitadel interview questions
  • Build a Bird’s-Eye-View Height GridNVIDIA · PHONE SCREENNVIDIA 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[][][] convolveValid(int[][][] input, int[][] kernels, int kernelHeight, int kernelWidth) {
      // write your code here
    }
}
Checking account…