Check whether a given Linked list is palindrome or not -
Design a data structure such that given values and its priority for each element it returns maximum priority elements and if priority is same then it return the items with equals probablitiy.
Example : Value - [2,3,4,5,6] -
Prioritity - [1,1,2,3,4]
Element number 1 && 2 have equal priority so they are removed with equal probability .
Solved this using a treemap<Priority,List> , whenever multiple elements with same priority occurs , use a random index and remove it from list .
Afterwards , the question was modified to introduce weight for each elements , such that if two elements have equal priority , their weight will dictate the probability of returning the item
Example : [1,2,3,4]
[2,3,4,5]
[4,5,6,7]
The answer would [1,2,4] , [1,2,5],[1,2,6],[1,2,7], [1,3,4] and so on