Check if an encoding represents a unique binary string | javascript program to check if given encoding represents a single string . ; Return true if sum becomes k ; Driver Code
function isUnique ( a , n , k ) { var sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += a [ i ] ; sum += n - 1 ; return ( sum == k ) ; } var a = [ 3 , 3 , 3 ] ; var n = a . length ; var k = 12 ; if ( isUnique ( a , n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;