Skip to content

1683. Invalid Tweets

Problem Statement

Table: Tweets

Column NameType
tweet_idint
contentvarchar

tweet_id is the primary key for this table. This table contains the all the tweets in a social media app.

Instructions

  • Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.
  • Return the result table in any order.
  • The result format is in the following example.

Example

Input: Tweets table

tweet_idcontent
1"Sunny day"
2"I love coding"

Output:

tweet_id
2

Explanation:

The content of the tweet with tweet_id 1 is "Sunny day" and the number of characters used is 9 which is not strictly greater than 15.

The content of the tweet with tweet_id 2 is "I love coding" and the number of characters used is 12 which is not strictly greater than 15.

Submissions

sql
SELECT tweet_id
FROM Tweets
WHERE CHAR_LENGTH(content) > 15;
python
import pandas as pd

def invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame:
    return tweets[tweets['content'].str.len() > 15][['tweet_id']]

Explanations

PostgreSQL
Submitted by @noeyislearning
  • SELECT tweet_id: This part of the statement specifies the column that you want to retrieve from the database. In this case, you're retrieving the tweet_id column.
  • FROM Tweets: This part of the statement specifies the table from which you want to retrieve the data. Here, Tweets is the table.
  • WHERE CHAR_LENGTH(content) > 15: This is a condition that filters the rows to include in the result set. It only includes rows where the character length of the content column is greater than 15. The CHAR_LENGTH function returns the number of characters in a string.
Pandas
Submitted by @noeyislearning