![]() |
VOOZH | about |
Design a program to take a sentence as an input, and then encode it into Pig Latin.
A Pig Latin is an encrypted word in English, generated by placing the first letter of each word at the end, and then adding "ay" to the end.
Examples:
Input: s = "nevermind youve got them"
Output: "evermindnay ouveyay otgay hemtay"Input: s = "sally knows best"
Output: "allysay nowskay estbay"
Approach: The problem can be solved by traversing the sentence and making the changes word by word, as follows:
Below is the java program to implement the approach:
allysay nowskay estbay
Time Complexity: O(N), where N is the length of sentence
Auxiliary Space: O(N)