GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday, 10 June 2022

[Solution] Expected move CodeChef Solution | CodeChef Problem Solution 2022

You are given a fair coin and two integers X and N.

You repeatedly flip the coin and perform the following operation based on the result:

  • If it lands on heads, then X will increase by 1. However, if X=N then X will not change.
  • If it lands on tails, X will decrease by 1.

You stop as soon as the value of X becomes 1.

Find the expected number of coin flips.

Note that it is guaranteed that under the given constraints, the answer is an integer and does not

    Solution Click Below:-  CLICK HERE


    Input Format

    • The first line contains a single integer T — the number of test cases. Then the test cases follow.

    • The first and only line of each test case contains two space separated integers X and N.

    Output Format

    For each testcase, output the expected number of coin flips.

    Constraints

    • 1T105

    No comments:

    Post a Comment