Convert a lowercase sentence to Pig Latin. Words are separated by single spaces. For a word that begins with a vowel (a, e, i, o, u), append "way" to the end. For a word that begins with one or more consonants, move all leading consonants to the end of the word and then append "ay". Return null for null input and return the input unchanged when it is blank.
Examples:
Input: str = 'hello'
Output: 'ellohay'
Explanation: Move the leading consonant h to the end and add ay
Input: str = 'apple'
Output: 'appleway'
Explanation: The word starts with a vowel so just add way
Input: str = 'smile'
Output: 'ilesmay'
Explanation: Move the consonant cluster sm to the end and add ay
Input: str = 'hello world'
Output: 'ellohay orldway'
Explanation: Each word is converted independently
Input: str = null
Output: null
Explanation: Null input returns null
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 October 2026 (Oct 4–15)Sponsored by FLXBL
Contest runs October 4 - 15. Complete challenges to climb the leaderboard!
Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes
Only the 12 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.