DatabricksOA #18
Find First Anagram Index
估计中等可在线判题
Given strings s and pattern of lowercase English letters, return the starting index of the earliest contiguous substring of s whose character frequencies exactly match those of pattern; if none exists, return -1.
Standard input/output and this site's supplementary ranges follow this problem's description.
输入格式
Two lines, containing s and pattern respectively. This site restricts the character set to ASCII lowercase letters; 1≤|s|,|pattern|≤200000.
输出格式
Output the earliest starting index (0-based); if none exists, output -1.
样例 1
输入:
cbaebabacd
abc
输出:
0
样例 2
输入:
abab
ab
输出:
0
样例 3
输入:
abc
cba
输出:
0