All challenges
Easy 0 solved 0% acceptance

Initials From a Name

Build uppercase initials from a full name.

What you'll learn

  • Split a name into words
  • Take the first letter of each word
  • Join and uppercase the result

Problem

Take the first letter of each word in full_name, uppercase it, and join the letters. Words are separated by one or more spaces.

Implement initials(full_name).

Input

full_name: A name made of letters and spaces.

Output

Return the initials, for example "ADL".

Constraints

1 ≤ length of full_name ≤ 200; it contains at least one letter

Examples

Example 1
Input:
full_name = "Ada Lovelace"

Expected output:
expected = "AL"
Input:
std::string full_name = "Ada Lovelace";

Expected output:
std::string expected = "AL";
Input:
string full_name = "Ada Lovelace";

Expected output:
string expected = "AL";

Explanation

A from Ada and L from Lovelace: "AL".

Example 2
Input:
full_name = "grace  brewster  hopper"

Expected output:
expected = "GBH"
Input:
std::string full_name = "grace  brewster  hopper";

Expected output:
std::string expected = "GBH";
Input:
string full_name = "grace  brewster  hopper";

Expected output:
string expected = "GBH";

Explanation

Extra spaces don't matter; the initials are uppercased: "GBH".

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

Each word contributes exactly one character: its first letter.

Hint 2

Traverse the name while tracking when a new word starts after spaces.

Hint 3

Watch for multiple spaces in a row so you only take one initial per word.

Expected complexity

O(n) time, O(1) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.