Mars Exploration

  • + 0 comments
    public static int marsExploration(String s) {
      // Write your code here
      int diff = 0;
      for (int i = 0; i < s.length(); i++) {
        if ((i % 3 == 0 || i % 3 == 2) && s.charAt(i) != 'S') {
          diff++;
        } else if (i % 3 == 1 && s.charAt(i) != 'O') {
          diff++;
        }
      }
      return diff;
    }