Size of both the strings
int n = S . length ( ) , m = P . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mapS . put ( S . charAt ( i ) , mapS . getOrDefault ( S . charAt ( i ) , 0 ) + 1 ) ; } for ( int i = 0 ; i < m ; i ++ ) { mapP . put ( P . charAt ( i ) , mapP . getOrDefault ( P . charAt ( i ) , 0 ) + 1 ) ; }