Mars Exploration

  • + 0 comments

    My TypeScript solution:

    function marsExploration(s: string): number {
        const length = s.length;
        let changedChars = 0;
        
        for (let i = 0; i < length; i++) {
            const originalChar = (
                i % 3 === 0 ||
                (i + 1) % 3 === 0
            )  ? "S" : "O";
            if (s[i] !== originalChar) changedChars ++;
            
        }
        
        return changedChars;
    }