Reverse each word and capitalise its first letter
Coding problemEasy-Medium
Given a sentence, reverse the letters of each word but keep the words in their places. Then change each reversed word so that its first character is upper case and all its other characters are lower case.
Words are separated by single spaces, and the sentence has no space at its start or end. Digits stay as they are; a word that starts with a digit after reversing simply has no letter to capitalise there.
Examples
Example 1
Input: s = "hello world"
Output: "Olleh Dlrow"
Example 2
Input: s = "SELENIUM Java"
Output: "Muineles Avaj"
Example 3
Input: s = "qa2 team"
Output: "2aq Maet"
Constraints
- The length of s is between 0 and 120,000
- Words hold English letters and digits and are separated by single spaces
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.