{"id":"3fd23b05-5b2a-461a-961b-3482841f0c1b","name":"Guess Number Higher Or Lower","description":"1. We are playing the Guess Game. The game is as follows:\r\n2. I pick a number from 1 to n. You have to guess which number I picked.\r\n3. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.\r\n4. You call a pre-defined API int guess(int num), which returns 3 possible results:\r\n a) -1: The number I picked is lower than your guess (i.e. pick < num).\r\n b) 1: The number I picked is higher than your guess (i.e. pick > num).\r\n c). 0: The number I picked is equal to your guess (i.e. pick == num).\r\n5. Return the number that I picked.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= n &lt;= 231 - 1\r\n1 &lt;= pick &lt;= n\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n static int pn=0;\n\n\nint guess(int val) {\n \n if (val == pn) {\n return 0;\n }\n else if (val < pn) {\n return 1;\n }\n else {\n return -1;\n }\n return 0;\n }\n\nint gg(int n)\n{\n return -1;\n \n}\n\nint main()\n{\n int n;\n cin>>n;\n int p;\n cin>>p;\n \n pn=p;\n int x=gg(n);\n cout<<x;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int guessNumber(int n) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n static int pn = 0; //picked number\r\n public static int guess(int val) {\r\n if (val == pn) {\r\n return 0;\r\n }\r\n else if (val < pn) {\r\n return 1;\r\n }\r\n else {\r\n return -1;\r\n }\r\n }\r\n\r\n public static void solve(int n, int pick) {\r\n pn = pick;\r\n System.out.println(guessNumber(n));\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int pick = scn.nextInt();\r\n\r\n solve(n, pick);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10 6","sampleOutput":"6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"2968d478-7b04-423e-a2ec-33521557d353","name":"Guess Number Higher Or Lower","slug":"guess-number-higher-or-lower","type":1}],"next":{"id":"71c32159-424b-41ec-ae45-ac6bc2e3e0a7","name":"Guess Number Higher Or Lower","type":3,"slug":"guess-number-higher-or-lower"},"prev":{"id":"9a7407c0-a964-4e64-a4ef-081e4dd13915","name":"Find The Element That Appears Once In Sorted Array MCQ","type":0,"slug":"find-the-element-that-appears-once-in-sorted-array-mcq"}}}

Guess Number Higher Or Lower

1. We are playing the Guess Game. The game is as follows: 2. I pick a number from 1 to n. You have to guess which number I picked. 3. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. 4. You call a pre-defined API int guess(int num), which returns 3 possible results: a) -1: The number I picked is lower than your guess (i.e. pick < num). b) 1: The number I picked is higher than your guess (i.e. pick > num). c). 0: The number I picked is equal to your guess (i.e. pick == num). 5. Return the number that I picked.

{"id":"3fd23b05-5b2a-461a-961b-3482841f0c1b","name":"Guess Number Higher Or Lower","description":"1. We are playing the Guess Game. The game is as follows:\r\n2. I pick a number from 1 to n. You have to guess which number I picked.\r\n3. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess.\r\n4. You call a pre-defined API int guess(int num), which returns 3 possible results:\r\n a) -1: The number I picked is lower than your guess (i.e. pick < num).\r\n b) 1: The number I picked is higher than your guess (i.e. pick > num).\r\n c). 0: The number I picked is equal to your guess (i.e. pick == num).\r\n5. Return the number that I picked.\r\n","inputFormat":"Input is managed for you\r\n","outputFormat":"Output is managed for you\r\n","constraints":"1 &lt;= n &lt;= 231 - 1\r\n1 &lt;= pick &lt;= n\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n static int pn=0;\n\n\nint guess(int val) {\n \n if (val == pn) {\n return 0;\n }\n else if (val < pn) {\n return 1;\n }\n else {\n return -1;\n }\n return 0;\n }\n\nint gg(int n)\n{\n return -1;\n \n}\n\nint main()\n{\n int n;\n cin>>n;\n int p;\n cin>>p;\n \n pn=p;\n int x=gg(n);\n cout<<x;\n \n return 0;\n}"},"java":{"code":"import java.util.*;\r\nimport java.io.*;\r\n\r\npublic class Main {\r\n\r\n public static int guessNumber(int n) {\r\n //write your code here\r\n return 0;\r\n }\r\n\r\n static int pn = 0; //picked number\r\n public static int guess(int val) {\r\n if (val == pn) {\r\n return 0;\r\n }\r\n else if (val < pn) {\r\n return 1;\r\n }\r\n else {\r\n return -1;\r\n }\r\n }\r\n\r\n public static void solve(int n, int pick) {\r\n pn = pick;\r\n System.out.println(guessNumber(n));\r\n }\r\n\r\n public static void main(String[]args) {\r\n //input work\r\n Scanner scn = new Scanner(System.in);\r\n int n = scn.nextInt();\r\n int pick = scn.nextInt();\r\n\r\n solve(n, pick);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10 6","sampleOutput":"6","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"cb36811c-9cd7-4d80-aa52-ae9b8409862a","name":"Searching And Sorting For Intermediate","slug":"searching-and-sorting-for-intermediate-10001","type":0},{"id":"2968d478-7b04-423e-a2ec-33521557d353","name":"Guess Number Higher Or Lower","slug":"guess-number-higher-or-lower","type":1}],"next":{"id":"71c32159-424b-41ec-ae45-ac6bc2e3e0a7","name":"Guess Number Higher Or Lower","type":3,"slug":"guess-number-higher-or-lower"},"prev":{"id":"9a7407c0-a964-4e64-a4ef-081e4dd13915","name":"Find The Element That Appears Once In Sorted Array MCQ","type":0,"slug":"find-the-element-that-appears-once-in-sorted-array-mcq"}}}
plane

Editor


Loading...

Guess Number Higher Or Lower

easy

1. We are playing the Guess Game. The game is as follows: 2. I pick a number from 1 to n. You have to guess which number I picked. 3. Every time you guess wrong, I will tell you whether the number I picked is higher or lower than your guess. 4. You call a pre-defined API int guess(int num), which returns 3 possible results: a) -1: The number I picked is lower than your guess (i.e. pick < num). b) 1: The number I picked is higher than your guess (i.e. pick > num). c). 0: The number I picked is equal to your guess (i.e. pick == num). 5. Return the number that I picked.

Constraints

1 <= n <= 231 - 1 1 <= pick <= n

Format

Input

Input is managed for you

Output

Output is managed for you

Example

Sample Input

10 6

Sample Output

6

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode