Code Room
Code reviewHardcr-g079
Subject Repeated workLevel Senior–Staff~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Review this Java method that ranks products for each user.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewjava
public List<Product> topForUser(User u, List<Product> products) {    products.sort((a, b) -> {        double sa = scorer.score(a, u);   // expensive ML scoring call        double sb = scorer.score(b, u);        return Double.compare(sb, sa);    });    return products.subList(0, Math.min(10, products.size()));}
Run or narrate your approach, then ask the coach.