Skip to content

Conversation

@krishjha1121
Copy link
Contributor

@krishjha1121 krishjha1121 commented Dec 30, 2025

👋 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 checkbox

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • 🚀 New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🧹 Code cleanup or refactor
  • 🧪 Tests added or updated
  • 📘 Documentation update

Summary by CodeRabbit

  • New Features
    • Added C++ implementations for 12 algorithm problems covering string manipulation, mathematical operations, and graph concepts
    • Most implementations are production-ready
    • One newly added solution requires attention for a potential boundary condition

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 30, 2025

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

@coderabbitai
Copy link

coderabbitai bot commented Dec 30, 2025

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ed945e and 64e9189.

📒 Files selected for processing (5)
  • Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
  • Leetcode/1558-course-schedule-iv/index.md
  • Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
  • Leetcode/1585-the-kth-factor-of-n/index.md
  • Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
📝 Walkthrough

Walkthrough

Batch 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

Cohort / File(s) Summary
Standard Algorithm Implementations
Leetcode/0952-word-subsets/index.md, Leetcode/1510-find-lucky-integer-in-an-array/index.md, Leetcode/1585-the-kth-factor-of-n/index.md, Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md
Frequency mapping, stack-based, and factorization implementations
String & Sorting Solutions
Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md, Leetcode/1561-rearrange-words-in-a-sentence/index.md, Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
Backtracking generation, word grouping by length, and prefix matching. Note: 1566 contains a potential out-of-bounds array access
Two-Pointer & Greedy Approaches
Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md, Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md, Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
Digit manipulation, two-pointer card selection, and modular arithmetic for subsequence counting
Graph & Matrix Solutions
Leetcode/1558-course-schedule-iv/index.md, Leetcode/1628-count-submatrices-with-all-ones/index.md
Transitive closure for prerequisite reachability and 2D DP for submatrix enumeration

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~35 minutes

Suggested reviewers

  • RAJ8664

Poem

🐰 Twelve problems solved with logic clear and bright,
Algorithm implementations taking flight,
From stacks to graphs, from strings to matrices fine,
Each solution a gem—though one needs your keen eye (bound-check mine)!
Hop along, reviewers, the code awaits your sight!

Pre-merge checks

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'added more leetcode soutions' is vague and generic, using non-descriptive language that doesn't convey specific information about which problems were solved or the nature of the changes. Revise the title to be more specific and descriptive, such as 'Add C++ solutions for LeetCode problems 952, 1510, 1516, and others' to clearly identify the primary change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@krishjha1121
Copy link
Contributor Author

added leetcode solutions

Copy link

@coderabbitai coderabbitai bot left a 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 specify 1 <= 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1da7d9a and 7ed945e.

📒 Files selected for processing (12)
  • Leetcode/0952-word-subsets/index.md
  • Leetcode/1510-find-lucky-integer-in-an-array/index.md
  • Leetcode/1516-the-k-th-lexicographical-string-of-all-happy-strings-of-length-n/index.md
  • Leetcode/1529-max-difference-you-can-get-from-changing-an-integer/index.md
  • Leetcode/1538-maximum-points-you-can-obtain-from-cards/index.md
  • Leetcode/1558-course-schedule-iv/index.md
  • Leetcode/1561-rearrange-words-in-a-sentence/index.md
  • Leetcode/1566-check-if-a-word-occurs-as-a-prefix-of-any-word-in-a-sentence/index.md
  • Leetcode/1570-final-prices-with-a-special-discount-in-a-shop/index.md
  • Leetcode/1585-the-kth-factor-of-n/index.md
  • Leetcode/1621-number-of-subsequences-that-satisfy-the-given-sum-condition/index.md
  • Leetcode/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 when nums[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 lsum for the first k cards, then iteratively swaps left cards for right cards and updates the maximum.

Comment on lines +88 to +95
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++;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

@vercel
Copy link

vercel bot commented Dec 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
prep Ready Ready Preview, Comment Dec 30, 2025 5:30pm

@RAJ8664 RAJ8664 merged commit 83bfcb5 into RAJ8664:main Dec 30, 2025
6 of 7 checks passed
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.

2 participants