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 toa 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?
↵
Let there be some elements and some groups. Each element associated to
↵
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?