Mars Exploration

Sort by

recency

|

1055 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can find the explanation here : https://youtu.be/Gf0fpGE83r4

    int marsExploration(string s) {
       int result = 0;
        string base = "SOS";
        for(int i = 0; i < s.size(); i++) if(s[i] != base[i%3]) result++;
        return result;
    }
    
  • + 0 comments

    My Javascript solution here:

    function marsExploration(s: string): number {
        const expected = "SOS".repeat(s.length / 3).split("");
        return expected.reduce((acc, curr, i) => acc + +(curr !== s[i]), 0);
    }
    
  • + 0 comments

    Haskell

    module Main where
    
    import Data.List (cycle)
    
    solve :: String -> Int
    solve = length . filter id . zipWith (/=) (cycle "SOS")
    
    main :: IO ()
    main = getLine >>= print . solve
    
  • + 0 comments

    for Python3 Platform

    def marsExploration(s):
        og_s = "SOS" * (len(s)//3)
        
        return len([(m, n) for m, n in zip(s, og_s) if m != n])
    
    s = input()
    
    res = marsExploration(s)
    
    print(res)
    
  • + 0 comments

    def marsExploration(s): # Write your code here repetitions = len(s) // 3 sos_str = "SOS" * repetitions

    dissimilar_count = sum(1 for a, b in zip(s, sos_str) if a != b)
    return dissimilar_count