-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add problem to company mapping #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| 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" | ||
| ] | ||
| }, | ||
| { | ||
| "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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Output schema is Title-based, not ID-based as stated in the PR objective. The generated mapping keys by Also applies to: 281-284 🤖 Prompt for AI Agents |
||
| "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 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard
pd.concatagainst an empty source list.If no
5. All.csvfiles are discovered, Line [171] raisesValueError: 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
🤖 Prompt for AI Agents