Find the String
Time limit3sMemory limit1024 MB
Count substrings of T that have the same equality pattern as P, meaning they are a bijective relabeling of P's letters. Lengths are up to 1,000,000.
- Level
Medium6 of 10
- Topics
- String matching, Hash map, Sliding window
- Solved
- No attempts yet
Problem
Two strings and made of lowercase English letters are called effectively equal if all of the following hold.
- and have the same length.
- For all integers and , if the -th and -th characters of are equal, then the -th and -th characters of are equal.
- For all integers and , if the -th and -th characters of are different, then the -th and -th characters of are different.
For example, aba and pqp are effectively equal. However, abca and abcb are not an effectively equal pair.
Given strings and , write a program that counts the contiguous substrings of that are effectively equal to .
For example, if abababbab and pqp, then the five substrings aba, bab, aba, bab, bab starting from the left of are effectively equal to .
You must write the following function.
int findP( char T [], char P [], int N, int M ):Tis an array (string) of lengthN+1.Pis an array of lengthM+1.TandPstore lowercase strings of lengthNandM. The last position ofTandPholds\0.findPmust return the number of contiguous substrings ofTthat are effectively equal toP.
Constraints
, .