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 'exactly 1' group at a time has a score. The data structure must support the following operations:
insert(el_id,grp_id,x): Insert element with idel_idwith a scorexto group with group_idgrp_idset(el_id,x): change the score of element with idel_idtox.set(grp_id,x): change the score of all elements in the group with idgrp_idtox.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?



