FastPrepVanilla RNN Hidden States
Problems/Vanilla RNN Hidden States

Vanilla RNN Hidden States

NVIDIA logoNVIDIA● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The handwritten RNN task matches the report at about 65%. The report omits the cell, shapes, and training scope; this practice uses a fixed-weight vanilla tanh forward pass.

Implement the forward pass of a vanilla recurrent neural network with a tanh cell over one input sequence. All weights are fixed. Compute the hidden state after every input. Only the forward pass is asked for.

Cell and sequence

  • inputs has T rows in time order. Each row has D features.
  • inputWeights has shape H x D, and recurrentWeights has shape H x H. Row r of each matrix produces hidden coordinate r.
  • bias and initialState each hold H values. Start with previous = initialState.

For input row t and each hidden coordinate r, compute:

value = bias[r]
      + sum(inputWeights[r][j] * inputs[t][j], j = 0..D-1)
      + sum(recurrentWeights[r][k] * previous[k], k = 0..H-1)
following[r] = tanh(value)

Every coordinate of following must read the same old previous vector. Only after the whole new vector is done does it become previous for the next input.

Returned states

  • Return a matrix with T rows and H columns. It holds the hidden state after each input, in time order.
  • Do not include initialState as an output row. An empty input sequence returns [].
  • Each output row must keep its own values, so later steps must not overwrite it. Do not change any of the given arrays.
  • Use plain loops and standard math functions such as tanh. Do not use outside tensor or ML libraries. Training, backpropagation, and LSTM gates are not part of this task.
  • Each returned value is accepted within absolute error 10^-6.

Function

rnnHiddenStates(inputs: double[][], inputWeights: double[][], recurrentWeights: double[][], bias: double[], initialState: double[]) → double[][]

Examples

Example 1

inputs = [[0],[1],[-1]]inputWeights = [[1]]recurrentWeights = [[0]]bias = [0]initialState = [0.75]return = [[0.0],[0.7615941559557649],[-0.7615941559557649]]

The recurrent weight is 0, so each step depends only on its input. The states are tanh(0), tanh(1), and tanh(-1).

Example 2

inputs = [[0],[0],[0]]inputWeights = [[0]]recurrentWeights = [[1]]bias = [0]initialState = [1]return = [[0.7615941559557649],[0.6420149920119999],[0.5662699759614797]]

The input contribution and bias are zero. Starting at 1, each step applies tanh to the previous hidden value. The starting 1 is not an output row.

Example 3

inputs = [[0.5,-1]]inputWeights = [[1,0],[0,1]]recurrentWeights = [[0,0],[0,0]]bias = [0,0]initialState = [0,0]return = [[0.46211715726000974,-0.7615941559557649]]

The input weight matrix is the identity, and all recurrent weights are zero. So each hidden value is just tanh of its own input, and the only returned row is [tanh(0.5), tanh(-1)].

Constraints

  • 0 <= T <= 30, 1 <= D <= 8, and 1 <= H <= 8.
  • Every array has the shape stated above. When T = 0, take D from the nonempty rows of inputWeights.
  • All values are finite. Entries of inputs, inputWeights, and bias lie in [-2, 2]. Entries of initialState lie in [-1, 1].
  • For each row r of recurrentWeights, sum(abs(recurrentWeights[r][k]), k = 0..H-1) <= 1. This limit keeps rounding errors from growing along the sequence.

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

  • Implement Cross-Entropy LossOpenAI · PHONE SCREENOpenAI interview questions
  • Scaled Dot-Product AttentionAmazon · PHONE SCREEN
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Apply a 2048 Board MoveGlean · PHONE SCREENGlean interview questions
  • Spiral Order with ObstaclesTemu · PHONE SCREENTemu interview questions
  • Logistic Regression DiagnosticsLinkedIn · PHONE SCREENLinkedIn interview questions
  • Spiral Matrix TraversalByteDance · PHONE SCREENByteDance interview questions
  • S-Shaped Matrix TraversalFox Corporation · PHONE SCREEN
  • Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions

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 double[][] rnnHiddenStates(double[][] inputs, double[][] inputWeights, double[][] recurrentWeights, double[] bias, double[] initialState) {
        // Return the hidden state after each input row.
    }
}
Checking account…