Skip to content

Add problem to company mapping - #1

Open
Sbrjt wants to merge 1 commit into
codeaashu:mainfrom
Sbrjt:main
Open

Add problem to company mapping#1
Sbrjt wants to merge 1 commit into
codeaashu:mainfrom
Sbrjt:main

Conversation

@Sbrjt

@Sbrjt Sbrjt commented Jun 6, 2026

Copy link
Copy Markdown

This PR adds a problem_company_mapping.json.

Sample structure:

{
    "Title": "1-bit and 2-bit Characters",
    "company": ["IXL","Quora"]
}

This data can be useful for browser extensions that inject company-wise tags for LeetCode problems. (I'm building one currently). Centralizing the data avoids each consumer maintaining separate copies.

I've included the python script used to generate it.
If it makes sense for the repo, I can set up a GitHub Action to auto-update the JSON.

@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

A new Jupyter notebook aggregates LeetCode problem data from company-specific CSV files, combining multiple sources into a single DataFrame, grouping problems by title, and outputting a JSON mapping of each problem title to its associated companies as a sorted unique list.

Changes

LeetCode Problem Aggregation Pipeline

Layer / File(s) Summary
Setup and Input Example
script.ipynb
Notebook imports Path and pandas, sets root directory, and demonstrates reading Google/5. All.csv with output display.
Multi-source Data Aggregation and Transformation
script.ipynb
Iterates over company subfolders, reads 5. All.csv from each (when present), concatenates DataFrames with company labels, groups by problem Title, and aggregates companies into sorted unique lists per title.
Output Serialization and Configuration
script.ipynb
Persists the problem-company mapping to problem_company_mapping.json as records-formatted JSON; includes notebook kernel and format metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A script hops through folders with care,
Reading problems from every lair,
Grouping by title, companies combined,
JSON output, so neatly aligned!
Data flows smooth—what a delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add problem to company mapping' directly corresponds to the main change: adding a Jupyter notebook that generates a JSON mapping from LeetCode problem titles to associated companies.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
script.ipynb (1)

30-137: ⚡ Quick win

Remove stored notebook outputs before commit.

Committed HTML/table outputs make diffs large and noisy and increase merge churn for regenerated data pipelines.

Also applies to: 187-255

🤖 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 30 - 137, The notebook contains committed cell
outputs (the "outputs" arrays and non-null "execution_count" values) which
should be removed; open the notebook (script.ipynb), clear all cell outputs and
set execution_count to null for each cell (remove any HTML/table blobs under the
"outputs" field), then recommit only the source cells. To prevent future
commits, add a notebook-cleaning hook (e.g., install/enable nbstripout or add a
.gitattributes rule to filter ipynb outputs) and update the repo docs so
contributors run the hook before committing.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@script.ipynb`:
- Around line 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.
- Around line 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".

---

Nitpick comments:
In `@script.ipynb`:
- Around line 30-137: The notebook contains committed cell outputs (the
"outputs" arrays and non-null "execution_count" values) which should be removed;
open the notebook (script.ipynb), clear all cell outputs and set execution_count
to null for each cell (remove any HTML/table blobs under the "outputs" field),
then recommit only the source cells. To prevent future commits, add a
notebook-cleaning hook (e.g., install/enable nbstripout or add a .gitattributes
rule to filter ipynb outputs) and update the repo docs so contributors run the
hook before committing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69f6c66e-b780-4cd5-9790-0dc8f185cbf1

📥 Commits

Reviewing files that changed from the base of the PR and between 7d899ce and 781c7d9.

📒 Files selected for processing (2)
  • problem_company_mapping.json
  • script.ipynb

Comment thread script.ipynb
Comment on lines +160 to +171
"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"

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".

Comment thread script.ipynb
Comment on lines +258 to +262
"summary = (\n",
" combined\n",
" .groupby('Title', as_index=False)['company']\n",
" .agg(lambda values: sorted(set(values)))\n",
")\n",

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant