Question: Your friend will give you an integer, n, and write down another integer, x, which is in[1,n]. The goal is to guess what x is.

Your friend will give you an integer, n, and write down another integer, x, which is in[1,n]. The goal is to guess what x is. So you will pick a number, y, which is in [1,n]. If y equals x, we win.However, if y is not x, we lose and pay tyour friend an amount equals to our guess, y, and they will let us know whether y is higher or lower than x. The game continues until you get the right number, or you do not have enough money to pay (since every time we get a wrong number, we have to pay money equals that number). If the game ends without getting the right number, you lose. However, we also have the option not to play the game.

You should design an algorithm in JAVA that takes as input the number n (i.e. the upperbound), the money you have m, and outputs 0 (not play) or 1 (play). The key is nding the minimum amount of money, min, that can guarantee winning the game. If you have enough money (i.e. m min), the algorithm should output1, otherwise 0. Last but not least, since you have to make a quick decision the proposed solution should not be slower than O(n^3). The function is defined as follows:

 Your friend will give you an integer, n, and write down

Test 1:

Input: n= 1 m =0

Output: 1

Test 2:

Input: n=3 m=1

Output: 0

public class Solution 1 public int playorNot Play Cint n int m 1 public class Solution 1 public int playorNot Play Cint n int m 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!