zarif_2002's blog

By zarif_2002, history, 6 years ago, In English

how can i find out a substring of minimum length having at least k times same character(for example k times a)of a string(please in C)

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
6 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Prefix sum the number of occurrences of character c. Then do the binary search for every s[i] and find prefix sum with biggest index j such that d[i]-d[j]>=k (if d[] is prefix sum). Answer is minimum of such i-j+1.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    what is prefix sum please?

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Prefix sum is array that for each prefix_sum[i] counts (in this case) number of character c from 0 (if string is 0-indexed) to i. How we do that, well prefix_sum[i]=prefix_sum[i-1]. And if s[i] is certain character that we want, increment prefix_sum[i] by 1.