Minimize given flips required to reduce N to 0 | C # program to implement the above approach ; Function to find the minimum count of operations required to Reduce N to 0 ; Stores count of bits in N ; Recurrence relation ; Driver code
using System ; class GFG { public static int MinOp ( int N ) { if ( N <= 1 ) return N ; int bit = ( int ) ( Math . Log ( N ) / Math . Log ( 2 ) ) + 1 ; return ( ( 1 << bit ) - 1 ) - MinOp ( N - ( 1 << ( bit - 1 ) ) ) ; } public static void Main ( ) { int N = 4 ; Console . WriteLine ( MinOp ( N ) ) ; } }