Acronym Generator - Problem

Generate an acronym from a given phrase by taking the first letter of each word and converting it to uppercase.

For example, 'Portable Network Graphics' becomes 'PNG'.

Rules:

  • Split the phrase into words by spaces
  • Take the first character of each word
  • Convert all letters to uppercase
  • Join them together without spaces

Input & Output

Example 1 — Basic Phrase
$ Input: phrase = "Portable Network Graphics"
Output: "PNG"
💡 Note: Take first letter of each word: 'P' from Portable, 'N' from Network, 'G' from Graphics, result is 'PNG'
Example 2 — Single Word
$ Input: phrase = "Hello"
Output: "H"
💡 Note: Only one word 'Hello', so acronym is just 'H'
Example 3 — Multiple Spaces
$ Input: phrase = "World Wide Web"
Output: "WWW"
💡 Note: Extra spaces are ignored, words are 'World', 'Wide', 'Web', acronym is 'WWW'

Constraints

  • 1 ≤ phrase.length ≤ 1000
  • phrase consists of letters and spaces
  • phrase contains at least one letter

Visualization

Tap to expand
INPUTALGORITHMRESULT"Portable Network Graphics"Input phrase withwords separated by spaces1Split into words["Portable", "Network", "Graphics"]2Extract first lettersP, N, G3Convert to uppercaseAlready uppercase4Concatenate lettersJoin into final stringPNGFinal acronymKey Insight:Extract first alphabetic character from each word by tracking word boundaries(start of string or after space) and converting to uppercase.TutorialsPoint - Acronym Generator | Split and Extract
Asked in
Google 25 Amazon 18 Microsoft 15 Apple 12
23.4K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen