Mars Exploration

Sort by

recency

|

1079 Discussions

|

  • + 0 comments

    In c# public static int marsExploration(string s) { var correctMessage = string.Concat(Enumerable.Repeat("SOS",s.Length/3)); return correctMessage.Where((c, i) => c != s[i]).Count(); }

  • + 0 comments
    # Mars Exploration 🚀
    def mars_exploration(s):
        e = "SOS" * (len(s) // 3) # expected message
        return sum( [1 for i in range(len(s)) if s[i] != e[i]] )
    
  • + 0 comments

    int marsExploration(char* s) { char* a = malloc(strlen(s)*sizeof(char)); strcpy(a,s); int count=0; for(int i=0;a[i]!='\0';i++){ if(a[i]!='S' && a[i]!='O') count++; } return count; } Why it is showing only some test cases are fail?

  • + 0 comments

    Here is my c++ solution

    int marsExploration(string s) { int sz = s.size(); string strSos("SOS");

    int no_sos = sz/ 3;
    
    for(int i = 0; i < no_sos-1; i++)
        strSos.append("SOS");
    
    int cnt = 0;
    for( int i = 0; i < sz; i++)
    {
        if( strSos[i] != s[i] )
            cnt++;
    }
    return cnt;
    

    }

  • + 0 comments

    C Solution:

    int marsExploration(char* s) {
        int count=0,i=0;
        char SOS[]="SOS";
        while(*s){
            if(i>=3){
                i=0;
            }
            if(SOS[i]!=*s){
                count++;
            }
            i++;
            s++;
        }
        return count;
    }