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!
Create an Account
Sign up to track your progress, earn points, and compete with others. Your solutions will be saved automatically.
Create accountHow 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
🏆 All Time Leaderboard
Contest runs January 1, 1970 - December 31, 9999. Complete challenges to climb the leaderboard!
Points are calculated for challenges completed during the contest period.