A question on data structures
Difference between en2 and en3, changed 20 character(s)
Today, I was asked in an interview to build a data structure as follows:↵

Let there be some elements and some groups. Each element associated to 
a group'exactly 1' group at a time has a score. The data structure must support the following operations:↵

1. `insert(el_id,grp_id,x)`: Insert element with id `el_id` with a score `x` to group with group_id `grp_id`↵
2. `set(el_id,x)`: change the score of element with id `el_id` to `x`.↵
3. `set(grp_id,x)`: change the score of all elements in the group with id `grp_id` to `x`.↵
4. `print(grp_id)`: print the max score element's id in that group. (Return any if multiple exist)↵

Constraints:↵

```↵
1 <= no_of_elements <= 1e6↵
1 <= no_of_groups <= 5↵
1 <= score <= 5↵
```↵




I couldn't solve it during the interview and also couldn't think of any solution later. Would someone please help?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English roycf123 2023-08-14 08:48:22 10 Tiny change: ' 1' group at a time has a sco' -> ' 1' group has a sco'
en3 English roycf123 2023-08-14 07:56:07 20 Tiny change: 'ciated to a group has a sco' -> 'ciated to 'exactly 1' group at a time has a sco'
en2 English roycf123 2023-08-13 21:18:49 26 (published)
en1 English roycf123 2023-08-13 21:15:35 849 Initial revision (saved to drafts)