← Openai Interview Insights

Openai·Software Engineer·Technical Phone Screen·Senior

Senior
Jun 2026

Summary

OpenAI Research Engineer ML coding round. One question but the follow-ups kept going deeper than I expected, and the dimension-checking got relentless by the end.

Questions Asked (1)

Q1

Implement a 1-nearest-neighbor classifier from scratch, then integrate it into a neural network forward pass. The interviewer probed on tensor dimensions and shapes throughout.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I'd seen a version of this floating around before so I wasn't totally blindsided, but the NN forward pass extension was a different beast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem scope and input/output tensor shapes, then implement a vectorized 1-NN classifier using pairwise distance computation. Next, integrate it as a custom layer in a neural network forward pass, ensuring shape compatibility and discussing trade-offs like computational complexity.

Pro tip: Explicitly state tensor shapes at each step and use broadcasting to avoid loops; this demonstrates strong shape intuition and efficiency, which interviewers at OpenAI value.

1. Clarify requirements and shapes

Ask about input dimensions, batch size, number of classes, and whether the classifier is used during training or inference. Define expected tensor shapes for support set and query set.

2. Implement 1-NN from scratch

Compute pairwise distances (e.g., Euclidean) between query and support points using broadcasting, then find the nearest neighbor and return its label. Discuss vectorization and complexity.

3. Integrate into neural network forward pass

Treat the 1-NN as a non-parametric layer that takes features from a neural network and outputs predictions. Ensure the forward pass handles batch dimensions and maintains differentiability if needed.

4. Address shape and dimension issues

Walk through tensor shapes at each operation, using unsqueeze/expand for broadcasting. Explain how to handle batch queries and multiple support points.

5. Discuss trade-offs and extensions

Compare 1-NN with parametric layers, mention computational cost, memory, and potential for gradient flow. Suggest alternatives like soft nearest neighbor or prototype networks.

Key Points to Mention

  • Vectorized distance computation using broadcasting (e.g., torch.cdist or manual expansion)
  • Tensor shape management: batch dimensions, feature dimensions, and support set size
  • Computational complexity: O(N*M*D) for N queries, M support points, D dimensions
  • Integration with neural networks: non-differentiable argmin, but can use softmax over negative distances for differentiability
  • Trade-offs: 1-NN is simple but sensitive to outliers and computationally expensive for large support sets
  • Potential use cases: few-shot learning, metric learning, or as a baseline

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.