Check whether a binary string can be formed by concatenating given N numbers sequentially | C # implementation of the approach ; Function that returns false if the number passed as argument contains digit ( s ) other than '0' or '1' ; Function that checks whether the binary String can be formed or not ; Empty String for storing the binary number ; check if a [ i ] can be a part of the binary String ; Conversion of int into String ; if a [ i ] can 't be a part  then break the loop ; possible to create binary String ; impossible to create binary String ; Driver code
using System ; public class Solution { public static bool isBinary ( int n ) { while ( n != 0 ) { int temp = n % 10 ; if ( temp != 0 && temp != 1 ) { return false ; } n = n / 10 ; } return true ; } public static void formBinaryStr ( int n , int [ ] a ) { bool flag = true ; string s = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( isBinary ( a [ i ] ) ) { s += " " + a [ i ] ; } else { flag = false ; break ; } } if ( flag ) { Console . Write ( s + " STRNEWLINE " ) ; } else { Console . Write ( " - 1 STRNEWLINE " ) ; } } public static void Main ( string [ ] args ) { int [ ] a = new int [ ] { 10 , 1 , 0 , 11 , 10 } ; int N = a . Length ; formBinaryStr ( N , a ) ; } }