Function to count maximum number of occurrences of s2 as subsequence in s1 by concatenating s1 , n1 times and s2 , n2 times
static int getMaxRepetitions ( String s1 , int n1 , String s2 , int n2 ) { int temp1 [ ] = new int [ 26 ] , temp2 [ ] = new int [ 26 ] ; for ( char i : s1 . toCharArray ( ) ) temp1 [ i - ' a ' ] ++ ; for ( char i : s2 . toCharArray ( ) ) temp2 [ i - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( temp2 [ i ] > temp1 [ i ] ) return 0 ; }