-
-
Notifications
You must be signed in to change notification settings - Fork 16
added more leetcode soutions #108
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
Conversation
|
@krishjha1121 is attempting to deploy a commit to the RAJ ROY's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Rate limit exceeded@RAJ8664 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 24 minutes and 48 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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 have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughBatch implementation of 13 Leetcode problem solutions in C++, replacing placeholder comments with complete algorithm implementations across respective Markdown template files. Changes introduce problem-specific logic for tasks including frequency counting, two-pointer traversal, backtracking, graph reachability, and stack-based approaches. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~35 minutes Suggested reviewers
Poem
Pre-merge checks❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
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. Comment |
|
added leetcode solutions |
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.
Actionable comments posted: 3
🧹 Nitpick comments (1)
Leetcode/1510-find-lucky-integer-in-an-array/index.md (1)
72-85: Consider using array-based frequency counting for efficiency.The C++ solution uses a
map<int,int>for frequency counting, while the Java solution in the same file uses an array-based approach with constraint-aware bounds. Since the problem constraints specify1 <= arr[i] <= 500, an array would provide O(1) access instead of O(log n) per operation.Additionally, the second loop (line 78) creates copies of the map pairs; using
const auto&would avoid unnecessary copying.🔎 Proposed refactor to use array-based approach
class Solution { public: int findLucky(vector<int>& arr) { vector<int> freq(501, 0); for (auto num : arr) { freq[num]++; } int res = -1; for (int i = 1; i <= 500; i++) { if (freq[i] == i) { res = i; } } return res; } };This approach aligns with the Java solution's efficiency and directly leverages the problem constraints.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
Leetcode/0952-word-subsets/index.mdLeetcode/1510-find-lucky-integer-in-an-array/index.mdLeetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.mdLeetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.mdLeetcode/1538-maximum-points-you-can-obtain-from-cards/index.mdLeetcode/1558-course-schedule-iv/index.mdLeetcode/1561-rearrange-words-in-a-sentence/index.mdLeetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.mdLeetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.mdLeetcode/1585-the-kth-factor-of-n/index.mdLeetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.mdLeetcode/1628-count-submatrices-with-all-ones/index.md
🧰 Additional context used
🪛 GitHub Actions: Deploy to GitHub Pages
Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
[error] 70-70: Build failed: SyntaxError in vite plugin Vue. Element is missing end tag in Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md (70:1). Command: npm run docs:build / vitepress build.
🔇 Additional comments (10)
Leetcode/1585-the-kth-factor-of-n/index.md (1)
78-92: LGTM! The solution correctly finds factors by iterating to √n and avoids duplicates when i² = n. Time complexity O(√n + k log k) is optimal for this problem.Leetcode/0952-word-subsets/index.md (1)
83-115: LGTM! The approach efficiently computes maximum character requirements from words2, then filters words1 in a single pass. Correct and well-structured implementation.Leetcode/1558-course-schedule-iv/index.md (1)
114-138: LGTM! The transitive closure computation correctly propagates prerequisites. The nested loops ensure that if j depends on i, all of i's prerequisites are added to j's set. For the constraint n ≤ 100, O(n³) is acceptable.Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md (1)
100-122: LGTM! The backtracking naturally generates strings in lexicographic order by iterating characters in ascending sequence. More efficient than the Java version which sorts post-generation. Clean separation of concerns with the private helper.Leetcode/1561-rearrange-words-in-a-sentence/index.md (1)
136-152: LGTM! Elegant use of map for automatic length-based grouping. Correctly processes the text: converts first char early, groups by length, concatenates in order (which preserves original order within same-length words), and capitalizes the result. Clean and efficient.Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md (1)
82-101: LGTM! Optimal O(n) solution using monotonic stack. The right-to-left traversal correctly finds the next element with price ≤ current price. Clean loop logic with proper empty-stack handling.Leetcode/1628-count-submatrices-with-all-ones/index.md (1)
139-170: LGTM! Clever approach that correctly counts submatrices. For each row range, the AND maintains which columns have all 1s, and findRes efficiently counts contiguous column-ranges using the consecutive-sum formula (1+2+...+L). Verified correctness on examples.Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md (1)
103-137: LGTM! Correctly implements greedy digit replacement while respecting the no-leading-zeros constraint. The logic properly distinguishes leading digit (position 0) from others, and the early break prevents unintended multiple replacements. Handles all edge cases correctly.Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md (1)
82-106: LGTM!The two-pointer algorithm with precomputed powers of 2 is correct. Sorting enables the invariant that all subsequences with min=
nums[i]and max in[nums[i], nums[j]]are valid whennums[i] + nums[j] <= target, yielding 2^(j-i) subsequences. Modulo arithmetic is applied consistently throughout.Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md (1)
91-111: Algorithm logic is sound.The two-pointer approach correctly explores all combinations of taking i cards from the left and (k-i) cards from the right, tracking the maximum sum at each step. The implementation accurately computes
lsumfor the first k cards, then iteratively swaps left cards for right cards and updates the maximum.
Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
Outdated
Show resolved
Hide resolved
Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
Outdated
Show resolved
Hide resolved
| for (int i = 0; i <= sentence.size(); i++){ | ||
| if (sentence[i] == ' ' ||i == sentence.size()){ | ||
| string prefix = sentence.substr(start, searchWord.size()); | ||
| if (searchWord == prefix) | ||
| return idx; | ||
| start = 1 + i; | ||
| idx++; | ||
| } |
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.
Fix out-of-bounds array access in loop.
Line 88 loops with condition i <= sentence.size(). When i == sentence.size(), line 89 accesses sentence[i], which is out of bounds (undefined behavior). The boundary check must occur before the access.
🔎 Proposed fix for out-of-bounds access
- for (int i = 0; i <= sentence.size(); i++){
- if (sentence[i] == ' ' ||i == sentence.size()){
+ for (int i = 0; i < sentence.size(); i++){
+ if (sentence[i] == ' '){
string prefix = sentence.substr(start, searchWord.size());
if (searchWord == prefix)
return idx;
start = 1 + i;
idx++;
}
}
+ // Check the last word after the loop
+ string prefix = sentence.substr(start, searchWord.size());
+ if (searchWord == prefix)
+ return idx;🤖 Prompt for AI Agents
In
Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
around lines 88 to 95, the loop currently uses i <= sentence.size() but accesses
sentence[i] before checking bounds which causes out-of-bounds when i ==
sentence.size(); fix by checking the boundary first: change the if to "if (i ==
sentence.size() || sentence[i] == ' ')" so you never index sentence at position
sentence.size(); keep the rest of the logic (substr and start/idx updates) the
same.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
👋 Hey there! Thank you for contributing to Prep 🚀
Please fill out this pull request template carefully to help us review your changes quickly.
Please check all that apply:
Place an "x" in the corresponding checkboxSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.