Easy · Hash Maps

Object as key

Given a list of students, each an {ID, Name} record, and a list of grade rows {Student: {ID, Name}, Grade}, return a {Student, Grade} row for every entry in the students list that has a grade row with the same ID and the same Name, in the order of the students list. A student listed twice gets a row each time; return an empty list if nothing matches.

Examples

Example 1

{
  "students": [
    {"ID": 1, "Name": "Ana"},
    {"ID": 2, "Name": "Ben"},
    {"ID": 3, "Name": "Cleo"},
    {"ID": 1, "Name": "Ben"}
  ],
  "grades": [
    {"Student": {"ID": 1, "Name": "Ana"}, "Grade": 95},
    {"Student": {"ID": 2, "Name": "Ben"}, "Grade": 80},
    {"Student": {"ID": 4, "Name": "Dan"}, "Grade": 70}
  ]
}

Output: {1,Ana} → 95, {2,Ben} → 80

Example 2

{
  "students": [
    {"ID": 7, "Name": "Mae"},
    {"ID": 8, "Name": "Lia"}
  ],
  "grades": [
    {"Student": {"ID": 7, "Name": "Mae"}, "Grade": 88},
    {"Student": {"ID": 8, "Name": "Lia"}, "Grade": 88}
  ]
}

Output: {7,Mae} → 88, {8,Lia} → 88

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Hash Maps problems