Generate Tag for Video Caption - Problem

You are given a string caption representing the caption for a video. You need to generate a valid tag for the video by performing the following actions in order:

1. Combine all words into a single camelCase string prefixed with '#'. A camelCase string is one where the first letter of all words except the first one is capitalized, and all other characters are lowercase.

2. Remove all non-English letters except the first '#' character.

3. Truncate the result to a maximum of 100 characters.

Return the generated tag after performing these operations on the caption.

Input & Output

Example 1 — Basic Case
$ Input: caption = "Hello World!"
Output: #helloWorld
💡 Note: Words are 'Hello' and 'World'. First word becomes lowercase 'hello', second becomes 'World'. Result: '#helloWorld'
Example 2 — With Numbers and Symbols
$ Input: caption = "Coding123 is FUN!!!"
Output: #codingIsFun
💡 Note: Extract words 'Coding', 'is', 'FUN'. Apply camelCase: 'coding' + 'Is' + 'Fun' = '#codingIsFun'
Example 3 — Single Word
$ Input: caption = "AWESOME"
Output: #awesome
💡 Note: Single word 'AWESOME' becomes lowercase 'awesome' as the first word. Result: '#awesome'

Constraints

  • 1 ≤ caption.length ≤ 105
  • caption consists of English letters, digits, spaces, and punctuation marks

Visualization

Tap to expand
Generate Tag for Video Caption INPUT Caption String: "Hello World!" Words Identified: Hello World! Word 1 Word 2 Input: caption = "Hello World!" ALGORITHM STEPS 1 Split into Words ["Hello", "World!"] 2 Apply camelCase First word: lowercase Others: capitalize first 3 Add # Prefix #helloWorld! 4 Remove Non-Letters Keep only a-z, A-Z, # "!" removed Transformation: "Hello" + "World!" --> #helloWorld FINAL RESULT Generated Tag: #helloWorld Character Breakdown: # h e l l o W o r prefix lowercase Capital Validation: OK Length: 11 chars (max 100) Output: #helloWorld Key Insight: Word-based processing splits caption into words, applies camelCase transformation where the first word is fully lowercase and subsequent words have their first letter capitalized. Non-letter characters (except the # prefix) are removed. Result is truncated to 100 characters if needed. TutorialsPoint - Generate Tag for Video Caption | Word-Based Processing Approach
Asked in
Meta 25 Twitter 30 TikTok 20 Instagram 15
23.5K Views
Medium Frequency
~15 min Avg. Time
890 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