Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions problem_company_mapping.json

Large diffs are not rendered by default.

322 changes: 322 additions & 0 deletions script.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,322 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "8a81eea2",
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path\n",
"\n",
"import pandas as pd\n",
"\n",
"root = Path.cwd()\n"
]
},
{
"cell_type": "markdown",
"id": "5fe8a598",
"metadata": {},
"source": [
"Eg df\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "74215ee0",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Difficulty</th>\n",
" <th>Title</th>\n",
" <th>Frequency</th>\n",
" <th>Acceptance Rate</th>\n",
" <th>Link</th>\n",
" <th>Topics</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>EASY</td>\n",
" <td>Two Sum</td>\n",
" <td>100.0</td>\n",
" <td>0.557770</td>\n",
" <td>https://leetcode.com/problems/two-sum</td>\n",
" <td>Array, Hash Table</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>MEDIUM</td>\n",
" <td>Add Two Numbers</td>\n",
" <td>75.2</td>\n",
" <td>0.462251</td>\n",
" <td>https://leetcode.com/problems/add-two-numbers</td>\n",
" <td>Linked List, Math, Recursion</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>HARD</td>\n",
" <td>Trapping Rain Water</td>\n",
" <td>73.7</td>\n",
" <td>0.651019</td>\n",
" <td>https://leetcode.com/problems/trapping-rain-water</td>\n",
" <td>Array, Two Pointers, Dynamic Programming, Stac...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>HARD</td>\n",
" <td>Median of Two Sorted Arrays</td>\n",
" <td>73.2</td>\n",
" <td>0.438146</td>\n",
" <td>https://leetcode.com/problems/median-of-two-so...</td>\n",
" <td>Array, Binary Search, Divide and Conquer</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>MEDIUM</td>\n",
" <td>Longest Substring Without Repeating Characters</td>\n",
" <td>70.1</td>\n",
" <td>0.369362</td>\n",
" <td>https://leetcode.com/problems/longest-substrin...</td>\n",
" <td>Hash Table, String, Sliding Window</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Difficulty Title Frequency \\\n",
"0 EASY Two Sum 100.0 \n",
"1 MEDIUM Add Two Numbers 75.2 \n",
"2 HARD Trapping Rain Water 73.7 \n",
"3 HARD Median of Two Sorted Arrays 73.2 \n",
"4 MEDIUM Longest Substring Without Repeating Characters 70.1 \n",
"\n",
" Acceptance Rate Link \\\n",
"0 0.557770 https://leetcode.com/problems/two-sum \n",
"1 0.462251 https://leetcode.com/problems/add-two-numbers \n",
"2 0.651019 https://leetcode.com/problems/trapping-rain-water \n",
"3 0.438146 https://leetcode.com/problems/median-of-two-so... \n",
"4 0.369362 https://leetcode.com/problems/longest-substrin... \n",
"\n",
" Topics \n",
"0 Array, Hash Table \n",
"1 Linked List, Math, Recursion \n",
"2 Array, Two Pointers, Dynamic Programming, Stac... \n",
"3 Array, Binary Search, Divide and Conquer \n",
"4 Hash Table, String, Sliding Window "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_csv(\"Google/5. All.csv\")\n",
"df.head()\n"
]
},
{
"cell_type": "markdown",
"id": "c0be7eaf",
"metadata": {},
"source": [
"Read and merge all csv files\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "9852b068",
"metadata": {},
"outputs": [],
"source": [
"df_list = []\n",
"\n",
"for folder in root.iterdir():\n",
"\n",
" csv = folder / \"5. All.csv\"\n",
"\n",
" if not csv.exists():\n",
" continue\n",
"\n",
" df = pd.read_csv(csv, usecols=['Title'])\n",
" df['company'] = folder.name\n",
" df_list.append(df)\n",
"\n",
"combined = pd.concat(df_list, ignore_index=True)\n"
Comment on lines +160 to +171

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Guard pd.concat against an empty source list.

If no 5. All.csv files are discovered, Line [171] raises ValueError: No objects to concatenate. Add an explicit check so failures are clear and actionable.

Proposed fix
 df_list = []

 for folder in root.iterdir():

     csv = folder / "5. All.csv"

     if not csv.exists():
         continue

     df = pd.read_csv(csv, usecols=['Title'])
     df['company'] = folder.name
     df_list.append(df)

+if not df_list:
+    raise FileNotFoundError(f"No '5. All.csv' files found under {root}")
+
 combined = pd.concat(df_list, ignore_index=True)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"for folder in root.iterdir():\n",
"\n",
" csv = folder / \"5. All.csv\"\n",
"\n",
" if not csv.exists():\n",
" continue\n",
"\n",
" df = pd.read_csv(csv, usecols=['Title'])\n",
" df['company'] = folder.name\n",
" df_list.append(df)\n",
"\n",
"combined = pd.concat(df_list, ignore_index=True)\n"
for folder in root.iterdir():
csv = folder / "5. All.csv"
if not csv.exists():
continue
df = pd.read_csv(csv, usecols=['Title'])
df['company'] = folder.name
df_list.append(df)
if not df_list:
raise FileNotFoundError(f"No '5. All.csv' files found under {root}")
combined = pd.concat(df_list, ignore_index=True)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@script.ipynb` around lines 160 - 171, The code calls pd.concat(df_list,
ignore_index=True) without guarding against df_list being empty; add an explicit
check before that line to handle the empty-case (e.g., if not df_list: raise a
clear ValueError or create an empty DataFrame) so the failure is actionable;
update the logic around the df_list accumulation and the combined assignment
(referencing df_list and combined) to either produce an empty DataFrame with the
expected columns or raise a descriptive error like "No '5. All.csv' files found,
nothing to concatenate".

]
},
{
"cell_type": "markdown",
"id": "3f2be5e0",
"metadata": {},
"source": [
"Problem : company mapping\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9bdf9733",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Title</th>\n",
" <th>company</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>01 Matrix</td>\n",
" <td>[Accenture, DoorDash, Flipkart, Graviton]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1-bit and 2-bit Characters</td>\n",
" <td>[IXL, Quora]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>132 Pattern</td>\n",
" <td>[IBM, Intuit]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2 Keys Keyboard</td>\n",
" <td>[Salesforce]</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>24 Game</td>\n",
" <td>[Huawei, Roku]</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Title company\n",
"0 01 Matrix [Accenture, DoorDash, Flipkart, Graviton]\n",
"1 1-bit and 2-bit Characters [IXL, Quora]\n",
"2 132 Pattern [IBM, Intuit]\n",
"3 2 Keys Keyboard [Salesforce]\n",
"4 24 Game [Huawei, Roku]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"summary = (\n",
" combined\n",
" .groupby('Title', as_index=False)['company']\n",
" .agg(lambda values: sorted(set(values)))\n",
")\n",
Comment on lines +258 to +262

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Output schema is Title-based, not ID-based as stated in the PR objective.

The generated mapping keys by Title, but the PR objective describes an IDcompany contract. This can break downstream consumers expecting stable numeric IDs.

Also applies to: 281-284

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@script.ipynb` around lines 258 - 262, The current aggregation builds the
mapping keyed by Title (using combined.groupby('Title')['company']...), but the
PR requires an ID→company mapping; change the grouping and key to use the unique
ID field instead of Title (e.g., use combined.groupby('ID',
as_index=False)['company'].agg(...)) and produce the output mapping keyed by ID
(apply same fix for the other occurrence around the 281-284 block), ensuring the
aggregated values remain the sorted unique company lists.

"summary.head()\n"
]
},
{
"cell_type": "markdown",
"id": "4236cf32",
"metadata": {},
"source": [
"Save json\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8fcc6676",
"metadata": {},
"outputs": [],
"source": [
"summary.to_json(\n",
" root / 'problem_company_mapping.json',\n",
" orient='records',\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e6b17f25",
"metadata": {},
"outputs": [],
"source": [
"# summary.to_csv(\n",
"# root / 'problem_company_mapping.csv',\n",
"# index=False\n",
"# )\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.14.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}