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.
- Prepare
- Algorithms
- Strings
- Mars Exploration
- Discussions
Mars Exploration
Mars Exploration
+ 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 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 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 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 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 ; }
Load more conversations
Sort 979 Discussions, By:
Please Login in order to post a comment