As reported: Morgan Stanley on-campus SDE intern OA (Aug 2025): three sections — debugging (Java, C or C++, 7 questions), an aptitude section, and intern coding (3 questions, two easy and one medium-hard, 60 minutes). Coding question 1: a space-separated string and an extra string are given. Each word is encoded: if it starts with a vowel, its first letter moves to the end of the word; in every case the extra string is then appended to the word, and then the word gets as many
'z'characters as its position in the sequence.
Given a sentence sentence of words separated by single spaces and a string suffix, encode the words one by one (positions start at 1):
- If the word starts with a vowel (
a,e,i,o,u, upper or lower case), move its first letter to the end of the word. - Append
suffix. - Append
'z'repeatedptimes, wherepis the word's position in the sentence.
Return the encoded words joined by single spaces.
Example 1
sentence = "apple banana orange", suffix = "ma"
-> "ppleamaz bananamazz rangeomazzz"
apple starts with a vowel → pplea → pplea + ma + z. banana is unchanged → banana + ma + zz. orange → rangeo + ma + zzz.
Example 2
sentence = "I love code", suffix = "xy"
-> "Ixyz lovexyzz codexyzzz"
Clarifications
- A one-letter word that is a vowel stays the same in step 1.
suffixmay be empty.- Letter case is kept as it is.
Constraints: the sentence has 1 to 300 words of 1 to 8 English letters each, separated by single spaces, with no leading or trailing spaces; 0 ≤ suffix.length ≤ 10, lowercase letters.
Code runner format: one JSON value per line: sentence, then suffix. Implement encodeWords(sentence, suffix); the harness prints the returned string.