Minimum steps to minimize n as per given condition | A tabulation based solution in Javascript ;
function getMinSteps ( n ) { let table = new Array ( n + 1 ) ; table . fill ( 0 ) ; table [ 1 ] = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( ! ( i % 2 ) && ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 2 ] ) ; else if ( ! ( i % 3 ) && ( i % 2 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , table [ i / 3 ] ) ; else if ( ! ( i % 2 ) && ! ( i % 3 ) ) table [ i ] = 1 + Math . min ( table [ i - 1 ] , Math . min ( table [ i / 2 ] , table [ i / 3 ] ) ) ; else table [ i ] = 1 + table [ i - 1 ] ; } return table [ n ] + 1 ; } ' ' ' ' ' ' let n = 10 ; document . write ( getMinSteps ( n ) ) ;