Easy · Hash Maps

Find most popular cost books

Given a list of books, each with an id and a cost, where one cost occurs more often than every other cost, return the ids of all books with that cost, in any order; an empty list of books returns an empty list.

Examples

Example 1

{
  "books": [
    {"id": "A", "cost": 10},
    {"id": "B", "cost": 20},
    {"id": "C", "cost": 10},
    {"id": "D", "cost": 30},
    {"id": "E", "cost": 20},
    {"id": "F", "cost": 10}
  ]
}

Output: [A, C, F]

Example 2

{
  "books": [
    {"id": "P", "cost": 5},
    {"id": "Q", "cost": 5},
    {"id": "R", "cost": 5},
    {"id": "S", "cost": 8}
  ]
}

Output: [P, Q, R]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Hash Maps problems