Skip to content

Practice Capitalize the Title

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2129
LeetCode Problem

Capitalize the Title

Problem Statement

For each space-separated word in title, lowercase the whole word if it has one or two letters. For longer words, uppercase its first letter and lowercase all remaining letters. Return the words joined in their original order with single spaces.

Source: Capitalize the Title on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
title = "First leTTeR of EACH Word"
Output
"First Letter of Each Word"

# Example 3

Input
title = "i lOve leetcode"
Output
"i Love Leetcode"

Constraints

1 <= title.length <= 100
title consists of words separated by a single space without any leading or trailing spaces.
Each word consists of uppercase and lowercase English letters and is non-empty.

Related LeetCode Problems

Practice more problems similar to Capitalize the Title.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.