Capitalize the Title

EasyString

Description

Given a string title consisting of words separated by spaces, capitalize each word that has length > 2, otherwise make it lowercase. Return the capitalized title.

Examples

Input:title = "capiTalIze tHe titLe"
Output:"Capitalize The Title"
Explanation:

Each word has length > 2, so all are capitalized: 'capiTalIze' → 'Capitalize', 'tHe' → 'The', 'titLe' → 'Title'.

Input:title = "i am a go PRO"
Output:"i am a go Pro"
Explanation:

Words with length ≤ 2 ('i', 'am', 'a', 'GO') are lowercased, while words with length > 2 ('PRO') are capitalized with only the first letter uppercase.

Input:title = "HELLO world MY friend"
Output:"Hello World my Friend"
Explanation:

Words longer than 2 characters ('HELLO', 'world', 'friend') get capitalized (first letter uppercase, rest lowercase), while 'MY' becomes 'my' since it has exactly 2 characters.

Constraints

  • 1 ≤ title.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!