-
-
Notifications
You must be signed in to change notification settings - Fork 16
. #107
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
. #107
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. |
📝 WalkthroughWalkthroughThe PR adds complete C++ implementations for eight Leetcode algorithm problems (0854, 0878, 0892, 0900, 0901, 0905, 0920, 0925) by replacing placeholder comments with fully functional solutions, plus minor spacing adjustments to problem 0936 and a cosmetic blank line to problem 0565. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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 |
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: 0
🧹 Nitpick comments (2)
Leetcode/0854-making-a-large-island/index.md (2)
172-173: Extract direction arrays to class constants to avoid redefinition.The direction vectors (delrow/delcol) are recreated in both the DFS function and the second loop. Extracting them as static class constants would improve maintainability and performance.
🔎 Proposed refactor
class Solution { +private: + static const int delrow[4]; + static const int delcol[4]; + public: int dfs(int row , int col , vector<vector<int>>& grid , int id){ int n = grid.size(); if(row < 0 || row >= n || col < 0 || col >= n || grid[row][col] != 1){ return 0; } grid[row][col] = id; - int delrow[] = {0 , 1 , 0 , -1}; - int delcol[] = {1 , 0 , -1 , 0}; int size = 1; for(int i = 0 ; i < 4 ; i++){Then add the definitions after the class:
const int Solution::delrow[4] = {0, 1, 0, -1}; const int Solution::delcol[4] = {1, 0, -1, 0};Also applies to: 202-203
205-206: Consider clearer variable names for row/column offsets in the second loop.Using
i_andj_(line 205-206) as renamed indices may reduce readability. Consider names likeneighbor_rowandneighbor_col.🔎 Proposed refactor
for(int x = 0 ; x < 4 ; x++){ - int i_ = i + delrow[x]; - int j_ = j + delcol[x]; - if(i_ >= 0 && i_ < n && j_ >= 0 && j_ < n && - grid[i_][j_] != 0) st.insert(grid[i_][j_]); + int neighbor_row = i + delrow[x]; + int neighbor_col = j + delcol[x]; + if(neighbor_row >= 0 && neighbor_row < n && neighbor_col >= 0 && neighbor_col < n && + grid[neighbor_row][neighbor_col] != 0) st.insert(grid[neighbor_row][neighbor_col]); }Also applies to: 211-211
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
Leetcode/0565-array-nesting/index.mdLeetcode/0854-making-a-large-island/index.mdLeetcode/0878-shifting-letters/index.mdLeetcode/0892-shortest-subarray-with-sum-at-least-k/index.mdLeetcode/0900-reordered-power-of-2/index.mdLeetcode/0901-advantage-shuffle/index.mdLeetcode/0905-length-of-longest-fibonacci-subsequence/index.mdLeetcode/0920-uncommon-words-from-two-sentences/index.mdLeetcode/0925-construct-binary-tree-from-preorder-and-postorder-traversal/index.mdLeetcode/0936-rle-iterator/index.md
💤 Files with no reviewable changes (1)
- Leetcode/0936-rle-iterator/index.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build Docs
🔇 Additional comments (9)
Leetcode/0565-array-nesting/index.md (1)
115-115: Cosmetic formatting change.No functional impact.
Leetcode/0920-uncommon-words-from-two-sentences/index.md (1)
106-122: Implementation is correct.The frequency map approach efficiently identifies uncommon words. Stringstream correctly tokenizes both sentences, and the final filter for
count == 1captures words appearing exactly once across both inputs.Leetcode/0901-advantage-shuffle/index.md (1)
68-91: Greedy algorithm is correctly implemented.The ordered
mapandupper_boundprovide an efficient greedy strategy: for each target, assign the smallest nums1 element that beats it. The fallback tomap.begin()when no element can beat the target is optimal for resource allocation.Leetcode/0878-shifting-letters/index.md (1)
95-110: Suffix sum optimization is correct.The solution correctly identifies that position
iis affected byshifts[i], shifts[i+1], ..., shifts[n-1]. Building the suffix array in reverse and applying modulo 26 shifts efficiently solves the problem in O(n) time.Leetcode/0900-reordered-power-of-2/index.md (1)
60-74: Digit-sorting approach is efficient and correct.Comparing sorted digit strings correctly determines if
n's digits can be rearranged to form a power of two. The loop range[0, 31)covers all relevant powers within the 10^9 constraint.Leetcode/0905-length-of-longest-fibonacci-subsequence/index.md (1)
105-129: DP solution with two-pointer optimization is correct.The algorithm efficiently identifies Fibonacci subsequences by fixing
currand using two pointers to find pairs wherearr[start] + arr[end] == arr[curr]. The DP semantics (tracking relative length) and return logic properly handle both found and not-found cases.Leetcode/0925-construct-binary-tree-from-preorder-and-postorder-traversal/index.md (1)
76-110: Recursive tree construction is correctly implemented.The algorithm properly uses the preorder root and postorder structure to recursively build subtrees. Hash map provides O(1) lookups for postorder indices, and recursive range calculations are correct.
Leetcode/0892-shortest-subarray-with-sum-at-least-k/index.md (1)
75-97: Monotonic deque approach is correctly implemented.The solution properly handles negative values by maintaining a deque of indices in increasing order of prefix sums. Front pops extract valid subarrays, while back pops maintain monotonicity to avoid missing optimal candidates. The algorithm achieves O(n) time complexity.
Leetcode/0854-making-a-large-island/index.md (1)
164-221: Algorithm is correct and handles edge cases properly.The C++ solution correctly:
- Uses DFS to label islands with unique IDs (2+) while tracking sizes in a map
- Iterates through each zero cell, collects adjacent island IDs in a set to avoid duplicates, and computes the maximum possible island size if flipped
- Handles edge cases (all 1s, all 0s, isolated islands, single cells)
The check
grid[row][col] != 1on line 168 efficiently prevents revisiting cells during DFS.
👋 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
New Features
Style
✏️ Tip: You can customize this high-level summary in your review settings.