Find the String having each substring with exactly K distinct characters | Java program to find the string having each substring with exactly K distinct characters ; Function to find the required output string ; Each element at index i is modulus of K ; Driver code ; Initialise integers N and K
import java . io . * ; class GFG { static void findString ( int N , int K ) { for ( int i = 0 ; i < N ; i ++ ) { System . out . print ( ( char ) ( ' A ' + i % K ) ) ; } } public static void main ( String [ ] args ) { int N = 10 ; int K = 3 ; findString ( N , K ) ; } }