Random Pick with weight Leetcode

Getting WA
My code–https://ide.geeksforgeeks.org/CFTBEr9tgB

@Bhawna can you explain your logic what you are doing.

https://www.youtube.com/watch?v=fWS0TCcr-lE I have followed this video but instead of using upper_bound ,I have written own Binary Search

@Bhawna
Is your binary search code implementing upper bound ?

It is finding bucket or index

@Bhawna hey your binary search should look like this
while(s<=e)
{
int mid=(s+e)/2;
if(s_[mid]==val)
{
ans=mid;
s = mid+1;
}
else if(s_[mid] > val)
{
e=mid-1;
}else{
s = mid+1;
}
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.