Блог пользователя werewolf97

Автор werewolf97, история, 3 года назад, По-английски

Given a string A. You need to solve Q queries. In each queries, you will be given a string B[i]. You need to find the count of the number of substrings of A which are anagrams of B[i].

Contraints:

1<=|A|, |B[i]|<=10^5 1<=Q<=10^5 summation|B[i]|<=2x10^5 All the strings consists of lowercase English letters.

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится +31 Проголосовать: не нравится

Provide a link to the statement or say where is this problem from, if you don't do this, i can't know if this problem is from a ongoing contest or not.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    No not from a live contest, was asked in an interview.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +35 Проголосовать: не нравится

      ain't never seen an interview problem with such detailed constraints on the number of queries as well as summation over all test cases.

»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

There are 1000 different values of len(B[i]) in Q queries. For each different value of len(B[i]), Iterate through A and store in map the cnt 26 length array of freq cnt for the length of substring. This takes O(1000*len(A)) and final ans can be done in O(1) per query.