Given a string, return a new string where characters at even indices (0, 2, 4, ...) are uppercase and characters at odd indices (1, 3, 5, ...) are lowercase. Return null for null input and return an empty string for empty input.

Examples:

Input: str = 'hello' Output: 'HeLlO' Explanation: H at index 0 (even), e at index 1 (odd), L at index 2 (even), l at index 3 (odd), O at index 4 (even)
Input: str = 'apex' Output: 'ApEx' Explanation: A at index 0 (even), p at index 1 (odd), E at index 2 (even), x at index 3 (odd)
Input: str = 'salesforce' Output: 'SaLeSfOrCe'
Input: str = null Output: null
Input: str = '' Output: ''
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay August 2026

Contest runs August 1 - 31. Complete challenges to climb the leaderboard!

Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In