Check if a binary string contains all permutations of length k | Java Program to Check If a String Contains All Binary Codes of Size K ; Unordered map of type string ; Driver code
import java . io . * ; import java . util . * ; class GFG { static boolean hasAllcodes ( String s , int k ) { Set < String > us = new HashSet < String > ( ) ; for ( int i = 0 ; i + k <= s . length ( ) ; i ++ ) { us . add ( s . substring ( i , i + k ) ) ; } return ( us . size ( ) == ( 1 << k ) ) ; } public static void main ( String [ ] args ) { String s = "00110110" ; int k = 2 ; if ( hasAllcodes ( s , k ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }