Mars Exploration

  • + 0 comments

    Java 8:

    public static int marsExploration(String s) {
            String sos = "SOS";
            int totalChangedLetters = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != sos.charAt(i % 3)) {
                    totalChangedLetters++;
                }
            }
            return totalChangedLetters;
        }