FastPrepTrain a Binary Recommender MLP
Problems/Train a Binary Recommender MLP

Train a Binary Recommender MLP

LinkedIn logoLinkedIn● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a LinkedIn phone screen. The report asks for a training pipeline for a binary recommender. It uses text embeddings of members and items and mentions a handwritten MLP. Its loader TODO does not match what the author later said, which is that loading was not needed. Here, you start with the embeddings already given and labels that match each row. We chose the architecture, the starting weights, the full-batch optimizer, the limits, the shape of the result and the number rules. No file access or LocalLLM service is needed. Our version is about 75% the same as the reported question.

Train a small binary recommender by following the exact steps below. Each row of members and items is an embedding vector that has already been computed. A row's zero-based index is its ID. Each row of pairs is [memberId, itemId, label], where 1 means clicked and 0 means skipped. Every ID exists. Repeated pairs are allowed and count as separate training examples.

For each labeled pair, build a feature vector x: the member embedding first, then the item embedding right after it. Do not average or normalize them. Let F be the combined feature width, H the hidden-layer width, and N the number of labeled pairs.

Model and initialization

You are given the starting parameters: hiddenWeights with shape H × F, hiddenBias and outputWeights of length H, and scalar outputBias. For one feature vector, compute:

  • a[h] = hiddenBias[h] + Σ hiddenWeights[h][d] × x[d].
  • r[h] = max(0, a[h]) (ReLU).
  • z = outputBias + Σ outputWeights[h] × r[h].
  • p = 1 / (1 + exp(-z)), the probability of a click.

Training

Run exactly steps updates of full-batch gradient descent. In each update, compute the mean binary cross-entropy over all N labeled pairs. Every pair uses the same current parameters. Find the gradient of this loss for every weight and bias. Then update all parameters at the same time with parameter -= learningRate × gradient. Do not update parameters between examples, shuffle the input, add regularization, or use momentum. The value a[h] is the ReLU preactivation. When it is exactly zero, use derivative 0. The derivative is also zero when the preactivation is negative, and one when it is positive. Each call must start with fresh state. Do not change the parameter arrays you are given.

To keep the loss numerically stable, compute it this way. One example with logit z and label y has loss max(z, 0) - y × z + log(1 + exp(-abs(z))). Use double-precision math. All inputs are finite, and with these learning rates every model value stays in a safe range for the sigmoid formula.

Result

After the last update, run one more forward pass. Return a double[] of length N + 1. The first N entries are the final click probabilities, in the same order as the labeled pairs. The last entry is their final mean binary cross-entropy. Do not return the probabilities from before an update, or the loss averaged over the training steps. Each returned number is accepted if its absolute or relative error is at most 10^-6.

Function

trainRecommender(members: double[][], items: double[][], pairs: int[][], hiddenWeights: double[][], hiddenBias: double[], outputWeights: double[], outputBias: double, steps: int, learningRate: double) → double[]

Examples

Example 1

members = [[1]]items = [[1]]pairs = [[0,0,1]]hiddenWeights = [[0.5,0.5]]hiddenBias = [0]outputWeights = [0]outputBias = 0steps = 1learningRate = 0.1return = [0.52497918747894,0.6443966600735709]

The feature vector is [1,1], the hidden activation is 1, and the initial probability is 0.5. The single positive example changes the output weight and bias from zero to 0.05 each. The hidden parameters do not change because the old output weight is zero. The final logit is 0.1, giving probability about 0.5249791875 and loss about 0.6443966601.

Example 2

members = [[1]]items = [[1]]pairs = [[0,0,0]]hiddenWeights = [[-0.5,-0.5]]hiddenBias = [0]outputWeights = [0]outputBias = 0steps = 1learningRate = 0.1return = [0.4875026035157896,0.6684596480132863]

The hidden preactivation is -1, so its activation and derivative are zero. For the negative label, only the output bias changes, from zero to -0.05. The final probability is about 0.4875026035, and the final negative-label loss is about 0.6684596480.

Constraints

  • Each embedding table has from 1 through 8 rows. Each table is rectangular, with its own width from 1 through 3; the two widths need not match.
  • 1 ≤ N ≤ 12, 1 ≤ H ≤ 4, and all parameter shapes match the combined width.
  • Every embedding value and initial parameter is finite and belongs to [-1, 1].
  • 1 ≤ steps ≤ 10 and 0.001 ≤ learningRate ≤ 0.1.
  • Each pair contains valid row IDs and a binary label. Duplicate and conflicting labels are allowed as separate examples.

More LinkedIn Phone Screen questions

  • Maximum Product of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Maximum Sum of a Contiguous SubarrayPHONE SCREEN · Seen Nov 2026
  • Merge Two Sorted ListsPHONE SCREEN · Seen Nov 2026
  • Sqrt(x)PHONE SCREEN · Seen Nov 2026
  • Total Years of Work ExperiencePHONE SCREEN · Seen Nov 2026
  • Sum an Arbitrary-Dimensional ArrayPHONE SCREEN · Seen Oct 2026
  • Known Words Matching Phone DigitsPHONE SCREEN · Seen Oct 2026
  • Inverse-Depth Nested List SumPHONE SCREEN · Seen Oct 2026
  • Valid Number with ExponentsPHONE SCREEN · Seen Oct 2026
  • Sort a Quadratic-Transformed ArrayPHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Light Source Hits: Sample, Compare, and FitOpenAI · PHONE SCREENOpenAI interview questions
  • Deterministic K-Means AssignmentsLyft · PHONE SCREENLyft interview questions
  • Deterministic K-Means AssignmentsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Knockout Tournament Win ProbabilityGoogle · PHONE SCREENGoogle interview questions
  • Scaled Dot-Product AttentionAmazon · PHONE SCREEN
  • Deterministic K-Means AssignmentsMicrosoft · PHONE SCREEN · ONSITE INTERVIEWMicrosoft interview questions
  • Implement K-Means ClusteringApple · PHONE SCREENApple interview questions
  • Parking Fee CalculatorBreeze · PHONE SCREEN
  • Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
  • Automation Pipeline, Part 1: Single WorkerPlaid · PHONE SCREENPlaid interview questions

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public double[] trainRecommender(double[][] members, double[][] items, int[][] pairs, double[][] hiddenWeights, double[] hiddenBias, double[] outputWeights, double outputBias, int steps, double learningRate) {
        // Write your code here
    }
}
Checking account…