Hello Programmers, In this post, you will learn how to solve HackerRank Mars Exploration Solution. This problem is a part of the HackerRank Algorithms Series.HackerRank Mars Exploration SolutionOne more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.HackerRank Mars Exploration SolutionTaskA 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, s, determine how many letters of the SOS message have been changed by radiation.Examples = ‘SOSTOT’The original message was SOSSOS. Two of the message’s characters were changed in transit.Function DescriptionComplete the marsExploration function in the editor below.marsExploration has the following parameter(s):string s: the string as received on EarthReturnsint: the number of letters changed during transmissionInput FormatThere is one line of input: a single string, s.Constraints1 <= length of s <= 99length of s modulo 3 = 0s will contain only uppercase English letters, ascii[A-Z].Sample Input 0SOSSPSSQSSOR Sample Output 03 Explanation 0s = SOSSPSSQSSOR, and signal length |s| = 12. They sent 4 SOS messages (i.e.: 12/3 = 4).Expected signal: SOSSOSSOSSOS Recieved signal: SOSSPSSQSSOR Difference: X X X Sample Input 1SOSSOT Sample Output 11 Explanation 1s = SOSSOT, and signal length |s| = 6. They sent 2 SOS messages (i.e.: 6/3 = 2).Expected Signal: SOSSOS Received Signal: SOSSOT Difference: X Sample Input 2SOSSOSSOS Sample Output 20 Explanation 2Since no character is altered, return 0.HackerRank Mars Exploration SolutionsMars Exploration Solution in C#include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <limits.h> #include <stdbool.h> int main(){ char* S = (char *)malloc(10240 * sizeof(char)); scanf("%s",S); int i; int count=0; for(i=0;S[i]!='\0';i+=3){ if(S[i]!='S'){ count++; } if(S[i+1]!='O'){ count++; } if(S[i+2]!='S'){ count++; } } printf("%d",count); return 0; }Mars Exploration Solution in Cpp#include <map> #include <set> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <string> #include <bitset> #include <cstdio> #include <limits> #include <vector> #include <climits> #include <cstring> #include <cstdlib> #include <fstream> #include <numeric> #include <sstream> #include <iostream> #include <algorithm> #include <unordered_map> using namespace std; int main(){ string str; cin >> str; string pattern = "SOS"; int count = 0; for (int i = 0; i < str.length(); ++i) { if (str[i] != pattern[i%3]) ++count; } cout << count << endl; return 0; }Mars Exploration Solution in Javaimport java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); String S = in.next(); int numChanged = 0; for(int i = 0; i < S.length(); i++) { if(i % 3 == 1) { if(S.charAt(i) != 'O') { numChanged++; } } else { if(S.charAt(i) != 'S') { numChanged++; } } } System.out.println(numChanged); } }Mars Exploration Solution in PythonX = raw_input() ans = 0 while X: ans += [1, 0][X[-1] == "S"] ans += [1, 0][X[-2] == "O"] ans += [1, 0][X[-3] == "S"] X = X[:-3] print ansMars Exploration Solution using JavaScriptprocess.stdin.resume(); process.stdin.setEncoding('ascii'); var input_stdin = ""; var input_stdin_array = ""; var input_currentline = 0; process.stdin.on('data', function (data) { input_stdin += data; }); process.stdin.on('end', function () { input_stdin_array = input_stdin.split("\n"); main(); }); function readLine() { return input_stdin_array[input_currentline++]; } /////////////// ignore above this line //////////////////// function main() { var S = readLine(); var res = 0; var sosCount = Math.floor(S.length/3); for (var i = 0; i<sosCount;i++){ if (S.charAt(i*3) !== 'S') res++; if (S.charAt(i*3+1) !== 'O') res++; if (S.charAt(i*3+2) !== 'S') res++; } process.stdout.write(res); }Mars Exploration Solution in Scalaobject Solution { def main(args: Array[String]) = { val in = new java.util.Scanner(System.in) var inputString = in.nextLine() var result = 0 while(inputString.nonEmpty) { result += countDiff(inputString.substring(0, 3)) inputString = inputString.substring(3) } println(result) } def countDiff(stringToChek: String) = { var result = 0 if(stringToChek.substring(0, 1) != "S") result += 1 if(stringToChek.substring(1, 2) != "O") result += 1 if(stringToChek.substring(2, 3) != "S") result += 1 result } }Mars Exploration Solution in Pascalvar a:array[0..2]of char; d,i,n:longint; s:string; procedure rd; begin readln(s); n:=length(s); a[0]:='S'; a[1]:='S'; a[2]:='O'; end; procedure xl; begin for i:=1 to n do if a[i mod 3]<>s[i] then inc(d); writeln(d); end; begin rd; xl; end.Disclaimer: This problem (Mars Exploration) is generated by HackerRank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.Next: HackerRank CamelCase Solution Post navigationHackerRank Two Characters Solution HackerRank CamelCase Solution