EasyNo. 1757
Recyclable and Low Fat Products — LeetCode 1757 Python Solution
- Topics
- Database
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
Table: Products +-------------+---------+ | Column Name | Type | +-------------+---------+ | product_id | int | | low_fats | enum | | recyclable | enum | +-------------+---------+ product_id is the primary key (column with unique values) for this table. low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.Example
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| product_id | int |
| low_fats | enum |
| recyclable | enum |
+-------------+---------+
product_id is the primary key (column with unique values) for this table.
low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
recyclable is an ENUM (category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.Python solution
import pandas as pd
def find_products(products: pd.DataFrame) -> pd.DataFrame:
rs = products[(products["low_fats"] == "Y") & (products["recyclable"] == "Y")]
rs = rs[["product_id"]]
return rsComplexity
- Time
- O(n log n)(typical)
- Space · auxiliary
- O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0175 | Combine Two Tables | Easy |
| 0176 | Second Highest Salary | Medium |
| 0177 | Nth Highest Salary | Medium |
| 0178 | Rank Scores | Medium |
| 0180 | Consecutive Numbers | Medium |
| 0181 | Employees Earning More Than Their Managers | Easy |
Frequently asked questions
- How hard is LeetCode 1757. Recyclable and Low Fat Products?
LeetCode 1757. Recyclable and Low Fat Products is rated Easy on LeetCode.
- What topics does LeetCode 1757. Recyclable and Low Fat Products cover?
LeetCode 1757. Recyclable and Low Fat Products is tagged Database on LeetCode.