Test if an event is in the x% most probable

Given the unsorted array arr containing the probability of n events, how to check if a given event is amongst the x% most probable events ?

For example, for n=3 and arr={0.3, 0.2, 0.5} (the event #0 occurs 30% of the time, event #1 20%, event #2 50%):

Try by yourself before displaying the solution by clicking here !

2022-07-11
in All, Riddle,
79 views
Copyright 2021-2024 Baillehache Pascal