Maximum limit upto which we can place digit . If tight is 1 , means number has already become smaller so we can place any digit , otherwise num [ pos ]
let limit = ( tight != 0 ? 9 : num [ pos ] ) ; for ( let dig = 0 ; dig <= limit ; dig ++ ) { let currCnt = cnt ;