{"id":"8c53fa17-a050-4094-8f5e-7920dca64b21","name":"Minimum Number Of Steps To Form N","description":"1. You are given a number N.\r\n2. You have to find the minimum number of operations needed to to reach N from 0.\r\n3. operations allowed are - \r\n -> Double the number.\r\n -> Add one to the number.","inputFormat":"A number N","outputFormat":"Check the sample output and question video.","constraints":"1 <= arr[i] <= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"5\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"02f58036-4f64-4bde-81b6-096289a63398","name":"Minimum Number Of Steps To Form N","slug":"minimum-number-of-steps-to-form-n","type":1}],"next":{"id":"472e4593-cc90-46c2-a929-2b7d9515a134","name":"Linear Equation Of N Variables","type":1,"slug":"linear-equation-of-n-variables"},"prev":{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","type":1,"slug":"minimum-number-of-steps-to-reduce-n"}}}

Minimum Number Of Steps To Form N

1. You are given a number N. 2. You have to find the minimum number of operations needed to to reach N from 0. 3. operations allowed are - -> Double the number. -> Add one to the number.

{"id":"8c53fa17-a050-4094-8f5e-7920dca64b21","name":"Minimum Number Of Steps To Form N","description":"1. You are given a number N.\r\n2. You have to find the minimum number of operations needed to to reach N from 0.\r\n3. operations allowed are - \r\n -> Double the number.\r\n -> Add one to the number.","inputFormat":"A number N","outputFormat":"Check the sample output and question video.","constraints":"1 <= arr[i] <= 10^6","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int n) {\r\n\t\t//write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tSystem.out.println(solution(n));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"10","sampleOutput":"5\r\n","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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"02f58036-4f64-4bde-81b6-096289a63398","name":"Minimum Number Of Steps To Form N","slug":"minimum-number-of-steps-to-form-n","type":1}],"next":{"id":"472e4593-cc90-46c2-a929-2b7d9515a134","name":"Linear Equation Of N Variables","type":1,"slug":"linear-equation-of-n-variables"},"prev":{"id":"f9db54d1-cfac-4538-8ab8-e94dfe78419b","name":"Minimum Number Of Steps To Reduce N","type":1,"slug":"minimum-number-of-steps-to-reduce-n"}}}
plane

Editor


Loading...

Minimum Number Of Steps To Form N

easy

1. You are given a number N. 2. You have to find the minimum number of operations needed to to reach N from 0. 3. operations allowed are - -> Double the number. -> Add one to the number.

Constraints

1 <= arr[i] <= 10^6

Format

Input

A number N

Output

Check the sample output and question video.

Example

Sample Input

10

Sample Output

5

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode