Short Problem Definition:
Sami’s spaceship crashed on Mars! She sends a series of
SOS messages to Earth for help.
time complexity is O(N)
space complexity is O(1)
We know that the message is basically a lot of concatenated SOS strings. There is no magic to this one.
S = raw_input().strip() errors = 0 for i in xrange(len(S)): if i % 3 == 0 and S[i] != 'S': errors += 1 if i % 3 == 1 and S[i] != 'O': errors += 1 if i % 3 == 2 and S[i] != 'S': errors += 1 print errors
If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.