Блог пользователя X-O__O-X

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

Given integers n and k such that

0 < n <= 10^6

0 < k <= 10^3

and a string S of length n.

Find any substring of length k in S with maximum number of occurrences. I don't care about the obvious complete search solution. Also, no need for complete solution. just some hints. what topic to look for ?etc.

example

n=13 k=3

abcabcabcabcd

ans is "abc" repeated 4 times.

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

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

Use the Z-algorithm

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

    Thank you. I just found idea using map<deque, int> counts; where I can construct any substring , ss, after the first one in O(1) but then I have to do : counts[ss]++; which I think should take O(|ss|*log n)