Mars Exploration

  • + 0 comments

    Python solution with O(n/3) time and O(1) time. I am not sure if there is a more efficient solution. If anyone can find something more efficient please comment:

    def marsExploration(s):
        i = 2
        res = 0
        while i < len(s):
            if s[i - 2] != 'S':
                res += 1
            if s[i - 1] != 'O':
                res += 1
            if s[i] != 'S':
                res += 1
                
            i += 3
        
        return res