Question: Java or python solution Operation 1: If the number is even then you can divide the number by 2. Operation 2: If the number is
Java or python solution
Operation 1: If the number is even then you can divide the number by 2. Operation 2: If the number is odd then you are allowed to perform either (n+1) or (n-1).
You need to print the minimum number of steps required to reduce the number N to 1 by performing the above operations.
Input Format
Input Format
Only one line that contains integer N
Constraints
Constraints
1 N 1,000,000
Output Format
Output Format
Minimum number of steps required to reduce the number N to 1
Sample Input 0
5
Sample Output 0
3
CODE GIVEN TO WRITE THE SOLUTION
import java.io.*; import java.util.*;
public class Solution {
public static void main(String[] args) { /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
