Recyclable and Low Fat Products — LeetCode 1757 Python Solution
EasyDatabase
- Problem
- #1757
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
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
SQL
+-------------+---------+
| 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
Python
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
| Measure | Complexity |
|---|---|
| Time | O(n log n) (typical) |
| Space | O(n) auxiliary |
Related problems
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.