Getting WA
My code–https://ide.geeksforgeeks.org/CFTBEr9tgB
Random Pick with weight Leetcode
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
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.