204. Capitalize the First Letter of Every Word

EasyStringString

Given a string s, capitalize the first letter of every word and convert all other letters to lowercase.

Words are separated by spaces. Return the resulting string.

Input: A single string s.

Output: The string with each word's first letter capitalized and rest lowercased.

Examples

Example 1
Input: hello world
Output: Hello World
Explanation: First letter of each word capitalized.
Example 2
Input: the quick brown fox
Output: The Quick Brown Fox
Explanation: Each word gets first-letter capitalization.
Example 3
Input: i love coding
Output: I Love Coding
Explanation: 'i'→'I', 'love'→'Love', 'coding'→'Coding'.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →