Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 94f7c1c

Browse files
Update readme.md
1 parent bb626d0 commit 94f7c1c

File tree

1 file changed

+113
-0
lines changed
  • LeetCode SQL 50 Solution/1757. Recyclable and Low Fat Products

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
Here’s a well-structured `README.md` for **LeetCode 1757 - Recyclable and Low Fat Products**, formatted for a GitHub repository:
2+
3+
```md
4+
# ♻️ Recyclable and Low Fat Products - LeetCode 1757
5+
6+
## 📌 Problem Statement
7+
You are given a table **Products** that contains information about products with respect to their fat content and recyclability.
8+
9+
- The **low_fats** column is an ENUM with values `'Y'` and `'N'`, where `'Y'` indicates the product is low fat.
10+
- The **recyclable** column is an ENUM with values `'Y'` and `'N'`, where `'Y'` indicates the product is recyclable.
11+
12+
Your task is to **find the IDs of products that are both low fat and recyclable**.
13+
14+
Return the result in **any order**.
15+
16+
---
17+
18+
## 📊 Table Structure
19+
20+
### **Products Table**
21+
| Column Name | Type |
22+
| ----------- | ---- |
23+
| product_id | int |
24+
| low_fats | enum |
25+
| recyclable | enum |
26+
27+
- `product_id` is the **primary key**.
28+
29+
---
30+
31+
## 📊 Example 1:
32+
33+
### **Input:**
34+
#### **Products Table**
35+
| product_id | low_fats | recyclable |
36+
| ---------- | -------- | ---------- |
37+
| 0 | Y | N |
38+
| 1 | Y | Y |
39+
| 2 | N | Y |
40+
| 3 | Y | Y |
41+
| 4 | N | N |
42+
43+
### **Output:**
44+
| product_id |
45+
| ---------- |
46+
| 1 |
47+
| 3 |
48+
49+
### **Explanation:**
50+
- Only products with `product_id` **1** and **3** are **both low fat and recyclable**.
51+
52+
---
53+
54+
## 🖥 SQL Solution
55+
56+
### ✅ **Approach:**
57+
- Filter the **Products** table for rows where `low_fats = 'Y'` and `recyclable = 'Y'`.
58+
- Return the corresponding `product_id`.
59+
60+
```sql
61+
SELECT product_id
62+
FROM Products
63+
WHERE low_fats = 'Y' AND recyclable = 'Y';
64+
```
65+
66+
---
67+
68+
## 🐍 Python (Pandas) Solution
69+
70+
### **Approach:**
71+
1. Load the **Products** table into a Pandas DataFrame.
72+
2. Filter the DataFrame to keep rows where both `low_fats` and `recyclable` are `'Y'`.
73+
3. Select and return the `product_id` column.
74+
75+
```python
76+
import pandas as pd
77+
78+
def recyclable_low_fat_products(products: pd.DataFrame) -> pd.DataFrame:
79+
# Filter rows where both low_fats and recyclable are 'Y'
80+
filtered = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')]
81+
# Select only the product_id column
82+
result = filtered[['product_id']]
83+
return result
84+
```
85+
86+
---
87+
88+
## 📁 File Structure
89+
```
90+
📂 Recyclable-Low-Fat-Products
91+
│── 📜 README.md
92+
│── 📜 solution.sql
93+
│── 📜 solution_pandas.py
94+
│── 📜 test_cases.sql
95+
│── 📜 sample_data.csv
96+
```
97+
98+
---
99+
100+
## 🔗 Useful Links
101+
- 📖 [LeetCode Problem](https://leetcode.com/problems/recyclable-and-low-fat-products/)
102+
- 🔍 [MySQL WHERE Clause](https://www.w3schools.com/sql/sql_where.asp)
103+
- 🐍 [Pandas DataFrame Filtering](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.loc.html)
104+
```
105+
106+
### Features of this `README.md`:
107+
✅ **Clear problem description with table structure**
108+
✅ **Example with detailed explanation**
109+
✅ **SQL and Python (Pandas) solutions with breakdown**
110+
✅ **Organized file structure for repository**
111+
✅ **Helpful links for further learning**
112+
113+
Let me know if you need any modifications!

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /