Mars Exploration

Sort by

recency

|

207 Discussions

|

  • + 0 comments
    def marsExploration(s):
        sos_count = len(s)//3
        original_sos = sos_count * "SOS"
        changed_chars = sum(1 for i in range(len(s)) if s[i] != original_sos[i])
        return changed_chars
    
  • + 0 comments
    def marsExploration(s):
        # Write your code here
        testStr = "SOS"
        lengthOfTestStr = len(testStr)
        index = 0
        result = 0
        for char in s:
            if char != testStr[index % lengthOfTestStr]:
                result += 1
            index += 1
        return result
    
  • + 0 comments
    def marsExploration(s):
        count = 0
        segments = re.findall(r'...', s)
        print(segments)
        
        for i in segments:
            for j, l in enumerate('SOS'):
                if l != i[j]:
                    count += 1
                    
        return count
    
  • + 0 comments

    Js solution:

    return s.split('').reduce((accumulator ,letter, currentIndex: number) => {
        if(
            ((currentIndex%3 === 0 || currentIndex%3 === 2) && letter !== 'S') ||
            (currentIndex%3 === 1 && letter !== 'O')
        ){
            return accumulator += 1;
        }
        return accumulator;
    }, 0);
    

    }

  • + 0 comments

    counter = 0 for i in range(0, len(s), 3): if s[i] !='S': counter+=1 if s[i+1] != 'O': counter+=1 if s[i+2] !='S': counter+=1 return counter