Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Impute Sparse Assessment Scores

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Impute Sparse Assessment Scores. Read through the requirements and the three tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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

Problem

You are given sparse assessment score data from Mercor assessments, where many candidate-question scores are missing and some recorded scores fall outside the valid 0-100 range. Write a PostgreSQL query that returns one row per candidate and assessment with a cleaned average score. Treat negative scores and scores above 100 as invalid, normalize valid scores to the 0-1 range, and impute missing or invalid scores using the average cleaned score for that question within the same assessment. If a question has no valid scores at all, fall back to the assessment-level cleaned average. Return only candidate-assessment pairs that have at least one assignment.

Schema

assessment_assignments
ColumnTypeDescription
assignment_idPKINTUnique assignment row
candidate_idINTCandidate taking the assessment
assessment_idINTAssessment identifier
question_idINTQuestion identifier within the assessment
assigned_atDATEDate the question was assigned
assessment_scores
ColumnTypeDescription
score_idPKINTUnique score row
assignment_idINTAssignment being scored
raw_scoreDECIMAL(5,2)Raw score, may be NULL or outside the valid range
assessments
ColumnTypeDescription
assessment_idPKINTAssessment identifier
assessment_nameVARCHAR(100)Assessment name
Tablesassessment_assignmentsassessment_scoresassessments
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results