Code RoomNull rating crashes average
MediumPrep Room Coding #1963

Null rating crashes average

Code reviewCode quality & reviewMid–Senior~16 min

Review this Java code computing a per-seller average rating to display on a dashboard.

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.

0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1double avgRating(List<Integer> ratings) {
2 int sum = 0;
3 for (Integer r : ratings) {
4 sum += r; // ratings may contain null for 'no score'
5 }
6 return (double) sum / ratings.size();
7}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.