Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Process Data and Verify With Tests

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Process Data and Verify With Tests. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

BASF quality engineers need a deterministic summary of sample viscosity readings from Ultramid® production batches. Write a Python function that groups readings by batch, calculates each batch's average viscosity, and marks the batch as PASS only when every reading is within the inclusive specification range.

The result must be easy to verify with automated tests. Return one summary per batch, sorted by batch_id.

Formal Specification

Implement summarize_ultramid_batches(records, minimum, maximum). records is a list of dictionaries containing a string batch_id and numeric viscosity. minimum and maximum are numeric inclusive bounds. Return a list of dictionaries with the keys batch_id, count, average_viscosity, and status. Round average_viscosity to two decimal places. If any reading for a batch is outside the bounds, its status is FAIL.

Constraints

  • 1 <= len(records) <= 10^5
  • 1 <= len(batch_id) <= 30
  • -10^6 <= viscosity, minimum, maximum <= 10^6
  • minimum <= maximum
  • Every record contains valid batch_id and viscosity fields

Function Signature

def summarize_ultramid_batches(records, minimum, maximum):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output