#C8195. Scrambled String Match

    ID: 52150 Type: Default 1000ms 256MiB

Scrambled String Match

Scrambled String Match

You are given two strings, \( s_1 \) and \( s_2 \). Your task is to determine whether a portion of the characters from \( s_1 \) can be rearranged to form \( s_2 \). In other words, check if for every character in \( s_2 \), the frequency in \( s_1 \) is at least as high.

For example, if \( s_1 = \texttt{'rkqodlw'} \) and \( s_2 = \texttt{'world'} \), then the answer is True. Conversely, if \( s_1 = \texttt{'katas'} \) and \( s_2 = \texttt{'steak'} \), then the answer is False.

Formally, let \( count_{s_1}(c) \) denote the number of occurrences of character \( c \) in \( s_1 \) and \( count_{s_2}(c) \) denote that in \( s_2 \). We require that \( count_{s_1}(c) \geq count_{s_2}(c) \) for every character \( c \) in \( s_2 \) to output True, otherwise output False.

inputFormat

The input consists of two lines:

  • The first line contains the string \( s_1 \).
  • The second line contains the string \( s_2 \).

outputFormat

Output a single line containing either True or False indicating whether a portion of \( s_1 \) can be rearranged to form \( s_2 \).

## sample
rkqodlw
world
True