DSA problem
Convert a String to Title Case
Given a string s, convert it to title case - capitalize the first letter of each word and make the rest lowercase.
Walk the string and capitalize the first character of every word (the first character overall and any character that follows a space), lowercasing the rest. Edge cases to handle: multiple consecutive spaces, leading or trailing spaces, empty words, and single-character words. This is a practical string-manipulation task seen in data cleaning, UI formatting, and content management systems. Python has str.title(), but it mishandles cases like it's (which becomes It'S); a manual implementation gives full control over the capitalization logic.
Examples
s = "hello world from algoinsight""Hello World From Algoinsight"Constraints
- 1 <= s.length <= 10^5
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.