We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. Choosing White Balls
  5. Discussions

Choosing White Balls

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 3 Discussions, By:

votes

Please Login in order to post a comment

  • tusharyadav7
    5 years ago+ 4 comments

    Hi I tried solving the question what we are actually trying to calculate is the probablity of the white ball being select at every iteration. According to one of the test cases the excepted input was - :

    6 4 BWBBBW

    and the output was - : 1.8555555556

    Now according to the explation let us try to solve it manually taking the following example - :

    In the first iteration we would have something like this

        We could either select the white ball at the second 
        place and have the next set as - BBBBW or BWBBB(if we excluded the 
        ball at the last place)
    
        The probablity of picking up the first white ball however would be 
        1/6+1/6+0+0+1/6+1/6 = 2/3 = 0.66666
    
        Now in the next case lets suppose we picked up BBBBW
        The probablity of picking up a white ball here would be
        (2/5*1/2) - (Here 1/2 is the probablity of picking up
        the lot from 2 lots from 1st iteration)
    
        Similarly if picked up the other lot that would be BWBBB. 
        The probablity of picking up a white ball again would be(2/5*1/2)
    
        Total Probablity would be the 2/3+2/5 = 16/15 = 1.06667
        The excepted output is 1.8555556
    

    Can somebdoy please explain what am I doing wrong here?

    1|
    Permalink
    View more Comments..
  • bruno_lemetayer
    2 years ago+ 1 comment

    Hi everyone,

    I'm dealing with some precision issues. For example expected > 19.4431179137 calculated > 19.4431084624 (before formatting : 19.443108462398186) I'm not making any roundings in my calculation, and I'm using Pyton 3 ... any hints ?

    0|
    Permalink
  • ahmedhos147
    5 years ago+ 0 comments

    Facing the same problem.

    0|
    Permalink

No more comments

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature