algorithm - given rank of a string, find all substrings in a given string with the given rank -
suppose rank pattern of string based on numbering characters 1 k if there k distinct characters in (there order provided on characters used, here assume < b < c.... , on example, can tell char(x) < or = or > char(y) in o|1| ) follow assigning numbers corresponding indices character occurs.
eg-
string - c d b c b, here b - 1, c - 2, d - 3
rank - 2 3 1 2 1 creating corresponding rank array
eg 2 -
string - d e g b c d here b - 1, c - 2, d - 3, e - 4, g - 5
rank - 3 5 4 1 2 3
(in short, assign smallest character value 1, next greater 2, , on )
now, question this:
given string s of size m , rank pattern in form of array p of size n; find no. of sub-strings of has given rank pattern? (m greater n make multiple possible solutions in string s)
eg.-
s c b d c e
p 1 3 2 1 4 there 2 substrings in s conform pattern p
here, in substring [0, 4] i.e c b d
rank 1 3 2 1 4
again in substring [3, 7] i.e d c e
rank 1 3 2 1 4
so, answer 2 here..
i know of o|sr| soln. , o|s(logr + rlogr)| soln. can better ?? if so, can tell me how??
Comments
Post a Comment