Check if a String Is an Acronym of Words - Problem
Given an array of strings words and a string s, determine if s is an acronym of words.
The string s is considered an acronym of words if it can be formed by concatenating the first character of each string in words in order. For example, "ab" can be formed from ["apple", "banana"], but it can't be formed from ["bear", "aardvark"].
Return true if s is an acronym of words, and false otherwise.
Input & Output
Example 1 — Basic Valid Acronym
$
Input:
words = ["alice","bob","charlie"], s = "abc"
›
Output:
true
💡 Note:
Taking first letters: 'a' from "alice", 'b' from "bob", 'c' from "charlie" gives "abc" which matches s
Example 2 — Invalid Acronym
$
Input:
words = ["an","apple"], s = "a"
›
Output:
false
💡 Note:
First letters are 'a' and 'a', forming "aa", but s = "a" has different length
Example 3 — Single Character Match
$
Input:
words = ["never"], s = "n"
›
Output:
true
💡 Note:
Single word "never" has first letter 'n' which matches s = "n"
Constraints
- 1 ≤ words.length ≤ 100
- 1 ≤ words[i].length ≤ 10
- 1 ≤ s.length ≤ 100
- words[i] and s consist of lowercase English letters
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array of words and target string
2
Extract
Take first character of each word
3
Compare
Check if extracted characters match target string
Key Takeaway
🎯 Key Insight: Simply compare first character of each word with corresponding position in target string
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code