CrackML by @ml.with.umang
Interview questions / ML Coding & PyTorch
ML Coding & PyTorch interview question

Transformation + Sorting AI Coding Problem

Implement a data transformation pipeline and return results in a specified ranking/order while preserving required ties.

mediumml codingEvidence 41/1001 source reportLinkedIn

The 60-second answer

Clarify the input/output contract, transformation rules, primary/secondary sort keys, and tie stability before coding. Transform in one pass, keep only the fields needed for ranking, then use the simplest sort/key function that preserves the required order.

Build the answer in this order

1
State tensor contract

Clarify the input/output contract, transformation rules, primary/secondary sort keys, and tie stability before coding.

2
Implement the mechanism

Transform in one pass, keep only the fields needed for ranking, then use the simplest sort/key function that preserves the required order.

3
Check numerics + gradients

State O(n log n) sorting cost and identify when a heap/top-k structure can reduce work to O(n log k).

4
Test shapes and edge cases

Test duplicate keys, missing fields, stable ties, and empty/singleton inputs.

A useful interview mental model

This is the shape of a strong answer—not a script to memorize.

01Shapes
02Forward pass
03Loss / grads
04Numerics
05Tests

Senior-level signal

  • Senior answers separate correctness of feature transformation from ranking logic so both can be unit tested independently.
  • If the data is too large for memory, discuss streaming top-k or external sort rather than pretending in-memory sort scales.

What the interviewer is really testing

Tensor fluency, shape reasoning, numerics, gradients, batching, device awareness, and the ability to debug—not API memorization.

Likely follow-up questions

What are the tensor shapes at each step?
Where could numerical instability or silent broadcasting appear?
How would you verify gradients and batched behavior?

Common weak-answer patterns

  • Ignoring shape, dtype, device, masking, or broadcasting assumptions.
  • Using a framework call without explaining the underlying operation.
  • Skipping gradient, numerical-stability, and batching checks.