Skip to content

seassion-003: easy sets of profit and duplicate#123

Merged
WazedKhan merged 3 commits into
mainfrom
session-003
Jun 8, 2026
Merged

seassion-003: easy sets of profit and duplicate#123
WazedKhan merged 3 commits into
mainfrom
session-003

Conversation

@WazedKhan

@WazedKhan WazedKhan commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features
    • Added solutions for three LeetCode problems:
      • "Contains Duplicate" (Easy)
      • "Max Profit" (Easy)
      • "Product of Array Except Self" (Medium)

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@WazedKhan, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 55 minutes and 56 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7f27c4a4-7a01-49d1-849f-9ae506dfd8fb

📥 Commits

Reviewing files that changed from the base of the PR and between 78e2bca and 7432797.

📒 Files selected for processing (1)
  • tests/test_leetcode_medium.py
📝 Walkthrough

Walkthrough

Adds three LeetCode solutions: containsDuplicate (set-based duplicate detection), maxProfit (single-pass min-price/max-profit), and productExceptSelf (prefix/postfix product composition).

Changes

LeetCode Solutions

Layer / File(s) Summary
Duplicate Detection Solution
LeetCode/easy/contains_duplicate_217.py
Solution.containsDuplicate iterates nums, tracks seen values in a set, returns True on first duplicate, otherwise False.
Stock Profit Maximization Solution
LeetCode/easy/max_profit_121.py
Solution.maxProfit maintains the minimum seen price and updates the maximum profit in a single pass over prices.
Product Except Self Solution
LeetCode/medium/product_except_self_238.py
Solution.productExceptSelf computes prefix and postfix products in two passes, then constructs the output array by multiplying prefix/postfix contributions for each index and returns it.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I am a rabbit hopping through arrays so neat,
I spot repeats and prices, and products complete,
With sets and passes I scamper and strive,
Three tiny solutions keeping algorithms alive! 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title mentions 'easy sets of profit and duplicate' which partially matches the changeset containing containsDuplicate, maxProfit, and productExceptSelf solutions, but contains a typo ('seassion' instead of 'session') and omits the medium-difficulty product_except_self solution.
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.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch session-003

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
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@LeetCode/easy/max_profit_121.py`:
- Line 6: The code initializes profit and cheapest_price with "profit,
cheapest_price = 0, prices[0]" which will raise IndexError for an empty prices
list; update the start of the max_profit function to handle the empty-input edge
case by either returning 0 immediately when not prices (early return) or by
initializing cheapest_price to float('inf') instead of prices[0] so the loop
works safely for empty or non-empty lists; modify references in the function
(profit, cheapest_price, and the main loop) accordingly.
- Around line 1-12: You have two copies of the same optimized implementation
(Solution.maxProfit) which duplicates maintenance; remove or refactor the
duplicate by keeping the canonical implementation that also contains
Solution.bruteForceMaxProfit (retain its file) and either delete this file or
replace its body with a simple import that re-exports the canonical
Solution.maxProfit; locate the duplicated method named Solution.maxProfit here
and the canonical Solution.maxProfit and Solution.bruteForceMaxProfit in the
other module, then update imports/exports so callers use only the canonical
implementation.
🪄 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: 85d6eb06-f67d-4f02-8ff1-0e2ee32c07c9

📥 Commits

Reviewing files that changed from the base of the PR and between a66b685 and 331f4e7.

📒 Files selected for processing (2)
  • LeetCode/easy/contains_duplicate_217.py
  • LeetCode/easy/max_profit_121.py

Comment on lines +1 to +12
from typing import List


class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit, cheapest_price = 0, prices[0]
for price in prices:
if price < cheapest_price:
cheapest_price = price
profit = max(profit, price - cheapest_price)

return profit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check for other solution files for problem 121

# Search for files containing "121" in the LeetCode/easy directory
fd -e py "121" LeetCode/easy/

# Check the content and compare implementations
rg -n "def maxProfit" LeetCode/easy/ --type py -C 10

Repository: WazedKhan/Problems

Length of output: 2555


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the other candidate file to compare implementations
echo "=== best_time_buy_sell_stock_121.py (relevant sections) ==="
nl -ba LeetCode/easy/best_time_buy_sell_stock_121.py | sed -n '1,220p'

echo "=== max_profit_121.py (entire file) ==="
nl -ba LeetCode/easy/max_profit_121.py | sed -n '1,160p'

# Check for any other 121-related python files in the directory
echo "=== other *121*.py files in LeetCode/easy ==="
fd -e py "121" LeetCode/easy/ | sort

Repository: WazedKhan/Problems

Length of output: 183


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Line counts ==="
wc -l LeetCode/easy/best_time_buy_sell_stock_121.py LeetCode/easy/max_profit_121.py

echo "=== rg locations for maxProfit/bruteForceMaxProfit ==="
rg -n "def (bruteForceMaxProfit|maxProfit)" LeetCode/easy/best_time_buy_sell_stock_121.py
rg -n "def maxProfit" LeetCode/easy/max_profit_121.py

echo "=== best_time_buy_sell_stock_121.py (show class + methods area) ==="
# Show around the first maxProfit definition and brute force method.
sed -n '1,120p' LeetCode/easy/best_time_buy_sell_stock_121.py
sed -n '120,220p' LeetCode/easy/best_time_buy_sell_stock_121.py

echo "=== max_profit_121.py ==="
cat -n LeetCode/easy/max_profit_121.py

echo "=== other *121*.py files in LeetCode/easy ==="
fd -e py "121" LeetCode/easy/ | sort

Repository: WazedKhan/Problems

Length of output: 3587


Consolidate duplicate LeetCode 121 solution files

  • LeetCode/easy/best_time_buy_sell_stock_121.py already contains Solution.maxProfit (optimized) alongside Solution.bruteForceMaxProfit.
  • LeetCode/easy/max_profit_121.py re-implements the same optimized maxProfit logic, creating duplicate maintenance.
    Recommend keeping one canonical file (likely best_time_buy_sell_stock_121.py) and removing/refactoring the other to avoid maintaining two copies of the same algorithm.
🤖 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 `@LeetCode/easy/max_profit_121.py` around lines 1 - 12, You have two copies of
the same optimized implementation (Solution.maxProfit) which duplicates
maintenance; remove or refactor the duplicate by keeping the canonical
implementation that also contains Solution.bruteForceMaxProfit (retain its file)
and either delete this file or replace its body with a simple import that
re-exports the canonical Solution.maxProfit; locate the duplicated method named
Solution.maxProfit here and the canonical Solution.maxProfit and
Solution.bruteForceMaxProfit in the other module, then update imports/exports so
callers use only the canonical implementation.


class Solution:
def maxProfit(self, prices: List[int]) -> int:
profit, cheapest_price = 0, prices[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Add validation for empty prices list.

Accessing prices[0] without validation will raise an IndexError if the input list is empty. This would cause a runtime crash.

🛡️ Proposed fix options

Option 1: Add early return for edge case

 def maxProfit(self, prices: List[int]) -> int:
+    if not prices:
+        return 0
     profit, cheapest_price = 0, prices[0]

Option 2: Use float('inf') initialization (matches reference implementation)

-    profit, cheapest_price = 0, prices[0]
+    cheapest_price = float('inf')
+    profit = 0
     for price in prices:
         if price < cheapest_price:
             cheapest_price = price
         profit = max(profit, price - cheapest_price)
🤖 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 `@LeetCode/easy/max_profit_121.py` at line 6, The code initializes profit and
cheapest_price with "profit, cheapest_price = 0, prices[0]" which will raise
IndexError for an empty prices list; update the start of the max_profit function
to handle the empty-input edge case by either returning 0 immediately when not
prices (early return) or by initializing cheapest_price to float('inf') instead
of prices[0] so the loop works safely for empty or non-empty lists; modify
references in the function (profit, cheapest_price, and the main loop)
accordingly.

@WazedKhan WazedKhan merged commit 536f305 into main Jun 8, 2026
3 checks passed
@WazedKhan WazedKhan deleted the session-003 branch June 8, 2026 04:26
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