Typing Course

Feedback
Settings
AccuracySpeedTimeErrors

100%

0WPM

0CPM

0s

0/0

"""⏎
of the strings.⏎
Time Complexity: O(nm)⏎
Psuedo Code: http://en.wikipedia.org/wiki/Rabin-Karp_algorithm⏎
"""⏎
from hashlib import md5⏎
def search(s, sub):⏎
"""⏎
Uses hashing to find any one of a set of pattern strings in a text.⏎
:param s: The string to be searched.⏎
:param sub: The substring to be searched for.⏎
:rtype: The indices of all occurences of where the substring is found in⏎
the string.⏎
"""⏎
n, m = len(s), len(sub)⏎
hsub_digest = md5(sub.encode('utf-8')).digest()⏎
offsets = []⏎
if m > n:⏎
return offsets⏎
for i in range(n - m + 1):⏎
if md5(s[i:i + m].encode('utf-8')).digest() == hsub_digest:⏎
if s[i:i + m] == sub:⏎
offsets.append(i)⏎
return offsets⏎

This course is for Pro members.

Check this out! Our plans start at only 2.69 USD per month

Upgrade your account and SAVE 40% NOW!
Already have a Pro account? Sign in
`~
1!
2@
3#
4$
5%
6^
7&
8*
9(
0)
-_
=+
backspace
tab
q
w
e
r
t
y
u
i
o
p
[{
]}
\|
capslock
a
s
d
f
g
h
j
k
l
;:
'"
enter
lshift
z
x
c
v
b
n
m
,<
.>
/?
rshift
fn
ctrl
lalt
lmeta
space
rmeta
ralt