Mars Exploration

  • + 0 comments
    public static int marsExploration(String str) {
        int count = 0;
        for(int i=1; i<=str.length();i++) {
            char ch = str.charAt(i-1);
            int loc = i%3;
            if((loc == 1 && ch != 'S') || 
                (loc == 2 && ch != 'O') || 
                (loc == 0 && ch != 'S')) 
            count++;
        }
        return count;
    }