HackerRank 'Mars Exploration' Solution

Martin Kysel · September 15, 2018

Short Problem Definition:

Sami’s spaceship crashed on Mars! She sends a series of SOS messages to Earth for help.

Mars Exploration

Complexity:

time complexity is O(N)

space complexity is O(1)

Execution:

We know that the message is basically a lot of concatenated SOS strings. There is no magic to this one.

Solution:

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

Twitter, Facebook

To learn more about solving Coding Challenges in Python, I recommend these courses: Educative.io Python Algorithms, Educative.io Python Coding Interview.