Check if a binary string contains all permutations of length k | C # Program to Check If a String Contains All Binary Codes of Size K ; Unordered map of type string ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool hasAllcodes ( string s , int k ) { HashSet < string > us = new HashSet < string > ( ) ; for ( int i = 0 ; i + k <= s . Length ; i ++ ) { us . Add ( s . Substring ( i , k ) ) ; } return us . Count == 1 << k ; } static void Main ( ) { string s = "00110110" ; int k = 2 ; if ( hasAllcodes ( s , k ) ) { Console . WriteLine ( " YES " ) ; } else { Console . WriteLine ( " NO " ) ; } } }