FastPrepBalanced Human, Model and Task Assignment

Balanced Human, Model and Task Assignment

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated

Problem statement

A labeling team rates answers written by AI models. There are humans raters, numbered from 0, and models AI models, also numbered from 0. There are ratings.length tasks, numbered from 0, and task t needs ratings[t] ratings.

One rating means one human reads one model's answer to one task. We write it as a triple [task, human, model].

The goal is to spread the work evenly over three kinds of pairs: human with model, human with task, and model with task. Build the triples with this greedy rule:

  1. Go through the tasks in order 0, 1, 2, .... For each task t, make its ratings[t] ratings one at a time.
  2. For the next rating of task t, give every pair of a human h and a model m a score. The score adds three counts over the ratings made so far: how many used h together with m (on any task), how many were ratings of task t by h, and how many were ratings of task t that used m.
  3. Choose the pair with the smallest score. If several pairs tie, choose the one whose human has made the fewest ratings so far (on all tasks). If that still ties, choose the one whose model has been used in the fewest ratings so far. If that still ties, choose the smaller human number, and then the smaller model number.
  4. Record the triple [t, h, m] and update the counts before making the next rating.

Return every triple in the order it was made. A task may need more ratings than there are humans or models; then some human or model is used on that task more than once.

Function

assignRatings(humans: int, models: int, ratings: int[]) → int[][]

Examples

Example 1

humans = 2models = 2ratings = [2,2]return = [[0,0,0],[0,1,1],[1,0,1],[1,1,0]]

Task 0, first rating: nothing has been used yet, so every pair scores 0 and has load 0. The smallest indexes win: human 0 with model 0.

Task 0, second rating: human 1 with model 1 scores 0, because neither of them has been paired with each other or used on task 0. Every other pair scores at least 1.

Task 1, first rating: human 0 with model 1 and human 1 with model 0 both score 0, and all loads are 1, so the smaller human index wins: human 0 with model 1. Task 1, second rating: human 1 with model 0 scores 0. In the end, every human worked with every model exactly once.

Example 2

humans = 3models = 2ratings = [1,1,1,1]return = [[0,0,0],[1,1,1],[2,2,0],[3,0,1]]

Each task needs one rating, so the task-human and task-model counts never matter here. Only the human-model counts and the loads do.

Task 0 takes human 0 with model 0. For task 1, every pair except (0, 0) scores 0. Humans 1 and 2 both have load 0, and model 1 has load 0 while model 0 has load 1. So (1, 1) and (2, 1) are equal on score, human load and model load, and the smaller human number makes (1, 1) win.

For task 2, human 2 has load 0, and both of its pairs score 0 and use a model with load 1, so the smaller model index wins: (2, 0). For task 3, every human has load 1. (0, 1) and (2, 1) score 0 and use model 1 with load 1, while (1, 0) uses model 0 with load 2. The smaller human index wins: (0, 1).

Example 3

humans = 2models = 3ratings = [3,1]return = [[0,0,0],[0,1,1],[0,0,2],[1,1,0]]

Task 0 needs 3 ratings, but there are only 2 humans, so one human must rate it twice.

First rating: (0, 0). Second rating: (1, 1) and (1, 2) score 0; both use human 1 and an unused model, so model 1 wins by index. Third rating: model 2 is still new to task 0, so (0, 2) and (1, 2) both score 1 (each human already rated task 0 once). Both humans have load 1 and model 2 has load 0, so human 0 wins by index.

Task 1, one rating: (1, 0) and (1, 2) score 0, while human 0 now has load 2. Both models have load 1, so model 0 wins by index.

Constraints

  • 1 <= humans, models <= 25
  • 1 <= ratings.length <= 500
  • 1 <= ratings[t] <= 10
  • The sum of all ratings[t] is at most 1000.

More OpenAI Phone Screen questions

Similar questions at other companies

OpenAI interview experiences

All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int[][] assignRatings(int humans, int models, int[] ratings) {
        // Write your code here.
    }
}
Checking account…