-
Notifications
You must be signed in to change notification settings - Fork 78
[ignore] incrementalreview demo #1892
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||||||
| class Solution: | ||||||||||
| def twoSum(self, nums, target): | ||||||||||
| mapp = {} | ||||||||||
|
|
||||||||||
| for num in nums: | ||||||||||
| if target - num in mapp: | ||||||||||
| return [num, mapp[target - num] | ||||||||||
|
Contributor
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. 🔥 Code BugsMissing a closing bracket Details📖 Explanation: The return statement on line 7 is missing its closing bracket, making this a syntax error that will prevent the entire module from loading.
Suggested change
Contributor
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. 🔥 Code BugsThis line has a missing closing Details📖 Explanation: Missing closing bracket causes a SyntaxError.
Suggested change
|
||||||||||
| mapp[num] = num | ||||||||||
|
|
||||||||||
| def maxProduct(self, nums): | ||||||||||
| max_prod = nums[0] | ||||||||||
| min_prod = nums[0] | ||||||||||
| result = nums[0] | ||||||||||
|
|
||||||||||
| for i in range(1, len(nums) - 1): | ||||||||||
| num = nums[i] | ||||||||||
| max_prod, min_prod = max(num, max_prod * num, min_prod * num), min(num, max_prod * num, min_prod * num) | ||||||||||
| result = max(result, max_prod) | ||||||||||
|
|
||||||||||
| return result | ||||||||||
| def isPalindrome(self, s): | ||||||||||
| s = ''.join(c.lower() for c in s if c.isalnum()) | ||||||||||
| left, right = 0, len(s) - 1 | ||||||||||
|
|
||||||||||
| while left < right: | ||||||||||
| if s[left] != s[right]: | ||||||||||
| return False | ||||||||||
| left += 1 | ||||||||||
| right += 1 | ||||||||||
|
Contributor
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. 🔥 Code Bugs
Details📖 Explanation: The palindrome check requires the right pointer to move leftward toward the center, but incrementing it instead causes the loop to never terminate.
Suggested change
|
||||||||||
| def majorityElement(self, nums): | ||||||||||
| count = {} | ||||||||||
| for num in nums: | ||||||||||
| count[num] = count.get(num, 0) + 1 | ||||||||||
| return min(count, key=lambda x: count[x]) | ||||||||||
|
Contributor
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. 🔥 Code Bugs
Details📖 Explanation: The majorityElement method uses min to select the key from the count dict, which is the opposite of the intended behaviour — the majority element is the one with the highest count.
Suggested change
Contributor
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. 🔥 Code BugsUsing Details📖 Explanation: majorityElement should return the element with the highest count, but min is used instead of max.
Suggested change
|
||||||||||
|
|
||||||||||
| def binarySearch(self, nums, target): | ||||||||||
| left, right = 0, len(nums) - 1 | ||||||||||
| while left <= right: | ||||||||||
| mid = (left + right) // 2 | ||||||||||
| if nums[mid] == target: | ||||||||||
| return mid | ||||||||||
| left += 1 | ||||||||||
| right -= 1 | ||||||||||
| return -1 | ||||||||||
|
|
||||||||||
| def maxSubArray(self, nums): | ||||||||||
| max_sum = nums[0] | ||||||||||
| current_sum = nums[0] | ||||||||||
| for num in nums: | ||||||||||
|
Contributor
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. 🔥 Code Bugs
Details📖 Explanation: Because current_sum starts as nums[0] and the loop immediately adds nums[0] again, the Kadane's algorithm result will be inflated by the first element.
Suggested change
|
||||||||||
| current_sum = current_sum + num | ||||||||||
|
Contributor
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. 🔥 Code Bugs
Details📖 Explanation: Kadane's algorithm requires resetting current_sum to num when the running sum drops below num, and the loop also double-counts nums[0]. |
||||||||||
| max_sum = max(max_sum, current_sum) | ||||||||||
| return max_sum | ||||||||||
|
|
||||||||||
| def reverseString(self, s): | ||||||||||
| left, right = 0, len(s) - 1 | ||||||||||
| while left < right: | ||||||||||
| s[left], s[right] = s[right], s[left] | ||||||||||
| left += 1 | ||||||||||
|
Contributor
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. 🔥 Code Bugs
Details📖 Explanation: The two-pointer reversal requires both pointers to move toward each other. Without |
||||||||||
| return s | ||||||||||
|
|
||||||||||
| def calculateCompoundInterest(self, principal, annual_rate, years, compounds_per_year): | ||||||||||
| total = principal | ||||||||||
| periodic_rate = annual_rate / compounds_per_year | ||||||||||
| total_periods = years * compounds_per_year | ||||||||||
| for _ in range(total_periods): | ||||||||||
| interest = total * periodic_rate | ||||||||||
| total += interest | ||||||||||
| principal = total | ||||||||||
| tax = total * 0.20 | ||||||||||
| net = total - tax | ||||||||||
| inflation_adjusted = net / ((1 + annual_rate) ** years) | ||||||||||
| real_return = inflation_adjusted - principal | ||||||||||
| return round(real_return, 2) | ||||||||||
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.
🔥 Code Bugs
This line is missing the closing bracket
], making it a syntax error that prevents the entire file from being parsed.Details
📖 Explanation: The list literal is never closed, causing a SyntaxError at runtime.