Search This Blog




mars exploration hacker rank solution javascript


Please refer this link for problem statement click here




Javascript program for mars exploration hackerrank solution


function marsExploration(message) {
    let sos = "SOS", count = 0;

    for (let i = 0; i < message.length; i++) {
        if (message.charAt(i) != sos.charAt(i % 3)) {
            count++;
        }
    }
    
    return count;
}



Time Complexity : O(n)

Space Complexity : O(1)


Post a Comment

0 Comments