We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Strings
  4. Mars Exploration
  5. Discussions

Mars Exploration

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 979 Discussions, By:

recency

Please Login in order to post a comment

  • alluarjunfake111
    2 days ago+ 0 comments

    #python3

    def marsExploration(s):`
        `# Write your code here```
        a=len(s)//3
        real="SOS"*a
        c=0
        b=list(zip(real,s))
        for i in b:
            if i[0]!=i[1]:
                c+=1
        return 
    
    0|
    Permalink
  • alluarjunfake111
    2 days ago+ 0 comments

    #python3 def marsExploration(s): # Write your code here a=len(s)//3 real="SOS"*a c=0 b=list(zip(real,s)) for i in b: if i[0]!=i[1]: c+=1 return c

    0|
    Permalink
  • kamalkumarkolis1
    4 days ago+ 0 comments

    **we need to find how many r mismatched with SOS so just iterate through 3 bits and check those 3 bits only **

    def marsExploration(s): k=0

    for i in range(0,len(s)-2,3):
        if s[i]!='S':
            k=k+1
        if s[i+1]!='O':
            k=k+1
        if s[i+2]!='S':
            k=k+1
    
    
    
    #k=len(s)//3
    return k
    
    0|
    Permalink
  • adeebahmed3337
    2 weeks ago+ 0 comments

    C++ O(n)

    int marsExploration(string s) {
    int res=0;
    for(int i=0;i<s.length();i+=3)
    {
       if(s[i]!='S' || s[i+1]!='O' || s[i+2]!='S' )
       {
           if(s[i]!='S')
           {
               res++;
           }
            if(s[i+1]!='O')
           {
               res++;
           }
            if(s[i+2]!='S')
           {
               res++;
           }
           
       }
    }
    return res;
    }
    
    0|
    Permalink
  • eslam_elwey1
    2 weeks ago+ 0 comments

    C solution

    int marsExploration(char* s) {
        int change =0 , i , j ;
        char arr[3] = {0} ;
        for (i=0 ;s[i];i+=3)
        {
            if (s[i]=='S')
            {
                arr[0] = 1 ;
            }
            if (s[i+1]=='O')
            {
                arr[1] = 1 ;
            }
            if (s[i+2]=='S')
            {
                arr[2] = 1 ;
            }
            for (j=0;j<3;j++)
            {
                if (arr[j]==0)
                {
                    change++;
                }
            }
            for (j=0;j<3;j++)
            {
                arr[j] = 0 ;
            }
        }
        
        return change ;
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy