{"id":"de4241d4-4abb-4455-872d-90dba1c860d8","name":"Min Jumps With +i -i Moves","description":"1. Given an integers X. \r\n2. The task is to find the minimum number of jumps to reach a point X in the number line starting from zero.\r\n3. The first jump made can be of length one unit and each successive jump will be exactly one unit longer than the previous jump in length. \r\n4. It is allowed to go either left or right in each jump.\r\n","inputFormat":"X = 8\r\nX = 9\r\n","outputFormat":"4\r\n-1 -> 2 -> 3 -> 4 (order of jumps)\r\n\r\n5\r\n1 -> 2 -> -3 -> 4 -> 5 (prder of jumps)\r\n","constraints":"None\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint minJumps(int x) {\n //write your code here\n}\n\n\nint main(){\n int x;\n cin>>x;\n\n int jumps = minJumps(x);\n cout<<jumps;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n // ~~~~~~~~~~~~User Section~~~~~~~~~~~\r\n public static int minJumps(int x) {\r\n // Write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int x = scn.nextInt();\r\n\r\n int jumps = minJumps(x);\r\n System.out.println(jumps);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"9","sampleOutput":"5","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"a27f69dc-1136-481c-8d92-b56d3803e859","name":"Min Jumps With +i -i Moves","slug":"min-jumps-with-i-i-moves","type":1}],"next":{"id":"8cb2e3ab-7f48-4637-8200-9a87551d43b7","name":"Min Jumps With +i -i Moves","type":3,"slug":"min-jumps-with-i-i-moves"},"prev":{"id":"a63a52be-5518-44b7-9169-12304d9f75b6","name":"Max Product Of Three Numbers MCQ","type":0,"slug":"max-product-of-three-numbers-mcq"}}}

Min Jumps With +i -i Moves

1. Given an integers X. 2. The task is to find the minimum number of jumps to reach a point X in the number line starting from zero. 3. The first jump made can be of length one unit and each successive jump will be exactly one unit longer than the previous jump in length. 4. It is allowed to go either left or right in each jump.

{"id":"de4241d4-4abb-4455-872d-90dba1c860d8","name":"Min Jumps With +i -i Moves","description":"1. Given an integers X. \r\n2. The task is to find the minimum number of jumps to reach a point X in the number line starting from zero.\r\n3. The first jump made can be of length one unit and each successive jump will be exactly one unit longer than the previous jump in length. \r\n4. It is allowed to go either left or right in each jump.\r\n","inputFormat":"X = 8\r\nX = 9\r\n","outputFormat":"4\r\n-1 -> 2 -> 3 -> 4 (order of jumps)\r\n\r\n5\r\n1 -> 2 -> -3 -> 4 -> 5 (prder of jumps)\r\n","constraints":"None\r\n","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nint minJumps(int x) {\n //write your code here\n}\n\n\nint main(){\n int x;\n cin>>x;\n\n int jumps = minJumps(x);\n cout<<jumps;\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n // ~~~~~~~~~~~~User Section~~~~~~~~~~~\r\n public static int minJumps(int x) {\r\n // Write your code here\r\n }\r\n\r\n //~~~~~~~~~~~~~~~~~~Input Management~~~~~~~~~~~~~~\r\n public static void main(String[] args) {\r\n Scanner scn = new Scanner(System.in);\r\n int x = scn.nextInt();\r\n\r\n int jumps = minJumps(x);\r\n System.out.println(jumps);\r\n }\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"9","sampleOutput":"5","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":"35f2cfb0-6f25-4967-b0c9-92f2384b9260","name":"Arrays And Strings For Intermediate","slug":"arrays-and-strings-for-intermediate-732","type":0},{"id":"a27f69dc-1136-481c-8d92-b56d3803e859","name":"Min Jumps With +i -i Moves","slug":"min-jumps-with-i-i-moves","type":1}],"next":{"id":"8cb2e3ab-7f48-4637-8200-9a87551d43b7","name":"Min Jumps With +i -i Moves","type":3,"slug":"min-jumps-with-i-i-moves"},"prev":{"id":"a63a52be-5518-44b7-9169-12304d9f75b6","name":"Max Product Of Three Numbers MCQ","type":0,"slug":"max-product-of-three-numbers-mcq"}}}
plane

Editor


Loading...

Min Jumps With +i -i Moves

easy

1. Given an integers X. 2. The task is to find the minimum number of jumps to reach a point X in the number line starting from zero. 3. The first jump made can be of length one unit and each successive jump will be exactly one unit longer than the previous jump in length. 4. It is allowed to go either left or right in each jump.

Constraints

None

Format

Input

X = 8 X = 9

Output

4 -1 -> 2 -> 3 -> 4 (order of jumps) 5 1 -> 2 -> -3 -> 4 -> 5 (prder of jumps)

Example

Sample Input

9

Sample Output

5

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode