HackerRank: Mars Exploration Solution in C

A space explorer’s ship crashed on Mars! They send a series of SOS messages to Earth for help.


Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal received by Earth as a string, determine how many letters of the SOS message have been changed by the radiation.

int marsExploration(char* s) {
    int error=0;
    for(int i=0 ; i<strlen(s); i+=3){
        if(s[i] != 'S' || s[i+1] != 'O' || s[i+2] != 'S'){   
            if(s[i]!='S') error++;
            if(s[i+1]!='O') error++;
            if(s[i+2]!='S') error++;    
return error;

Leave a Comment