Invalid Tweets - Problem

You are given a table Tweets containing tweet information from a social media app.

Problem: Find the IDs of invalid tweets where the content has strictly more than 15 characters.

Table Structure:

  • tweet_id (int): Primary key, unique identifier for each tweet
  • content (varchar): Tweet content with alphanumeric characters, '!', or ' ' only

Return the result in any order.

Table Schema

Tweets
Column Name Type Description
tweet_id PK int Primary key, unique identifier for each tweet
content varchar Tweet content consisting of alphanumeric characters, '!', or ' ' only
Primary Key: tweet_id
Note: Contains all tweets in the social media app

Input & Output

Example 1 — Mixed Valid and Invalid Tweets
Input Table:
tweet_id content
1 Hello World!
2 This is a very long tweet content that exceeds limit
3 Short tweet
Output:
tweet_id
2
💡 Note:

Tweet 1 has 12 characters, Tweet 3 has 11 characters (both ≤ 15, so valid). Tweet 2 has 54 characters (> 15, so invalid). Only tweet_id 2 is returned.

Example 2 — All Valid Tweets
Input Table:
tweet_id content
1 Hi there!
2 Good morning
3 15 char exactly
Output:
tweet_id
💡 Note:

All tweets have 15 or fewer characters. Tweet 1: 9 chars, Tweet 2: 12 chars, Tweet 3: 15 chars exactly. Since we need strictly greater than 15, no tweets are invalid.

Example 3 — Edge Case with Exactly 16 Characters
Input Table:
tweet_id content
1 Exactly16charstr
2 Normal tweet!
Output:
tweet_id
1
💡 Note:

Tweet 1 has exactly 16 characters, which is strictly greater than 15, making it invalid. Tweet 2 has 13 characters and is valid.

Constraints

  • 1 ≤ tweet_id ≤ 10^5
  • content consists of alphanumeric characters, '!', or ' ' only
  • 1 ≤ content.length ≤ 100

Visualization

Tap to expand
Invalid Tweets Problem OverviewStep 1: Input Datatweet_idcontent1Hello World!2Very long tweet...Step 2: Apply FilterWHERELENGTH(content) > 15Step 3: Outputtweet_id2
Understanding the Visualization
1
Input
Tweets table with tweet_id and content
2
Filter
Apply LENGTH(content) > 15 condition
3
Output
Return tweet_id of invalid tweets
Key Takeaway
🎯 Key Insight: Use LENGTH() function to validate text constraints efficiently in SQL
Asked in
Meta 15 Twitter 12 TikTok 8
25.4K Views
High Frequency
~5 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