Minimum steps to reduce N to 0 by given operations | Java program for the above approach ; Function to find the minimum number to steps to reduce N to 0 ; Base case ; Recursive Call to count the minimum steps needed ; Return the answer ; Driver Code ; Given Number N ; Function Call
class GFG { static int minDays ( int n ) { if ( n < 1 ) return n ; int cnt = 1 + Math . min ( n % 2 + minDays ( n / 2 ) , n % 3 + minDays ( n / 3 ) ) ; return cnt ; } public static void main ( String [ ] args ) { int N = 6 ; System . out . print ( minDays ( N ) ) ; } }