Check if an encoding represents a unique binary string | Java program to check if given encoding represents a single string . ; Return true if sum becomes k ; Driver Code
import java . io . * ; class GFG { static boolean isUnique ( int [ ] a , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; sum += n - 1 ; return ( sum == k ) ; } static public void main ( String [ ] args ) { int [ ] a = { 3 , 3 , 3 } ; int n = a . length ; int k = 12 ; if ( isUnique ( a , n , k ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }