Skip to content

Conversation

@krishjha1121
Copy link
Contributor

@krishjha1121 krishjha1121 commented Dec 29, 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 complete C++ solutions for eight Leetcode algorithm problems: Largest Island, Shifting Letters, Shortest Subarray, Reordered Power of 2, Advantage Shuffle, Longest Fibonacci Subsequence, Uncommon Words, and Binary Tree Construction.
  • Style

    • Applied minor formatting improvements and code cleanup across solution files.

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

@vercel
Copy link

vercel bot commented Dec 29, 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 29, 2025

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Graph & Island Algorithms
Leetcode/0854-making-a-large-island/index.md
Added dfs() helper and largestIsland() method implementing island labeling and area computation using DFS and neighborhood inspection
String Manipulation
Leetcode/0878-shifting-letters/index.md, Leetcode/0920-uncommon-words-from-two-sentences/index.md
Implemented character shift logic via suffix sums and word frequency mapping; tokenizes input and filters by occurrence count
Sequence & Subarray Problems
Leetcode/0892-shortest-subarray-with-sum-at-least-k/index.md, Leetcode/0905-length-of-longest-fibonacci-subsequence/index.md
Added monotonic deque approach for subarray validation and DP-based Fibonacci subsequence length computation
Permutation & Lookup Algorithms
Leetcode/0900-reordered-power-of-2/index.md, Leetcode/0901-advantage-shuffle/index.md
Implemented digit reordering comparison via lambda helper and greedy element selection using frequency maps
Tree Construction
Leetcode/0925-construct-binary-tree-from-preorder-and-postorder-traversal/index.md
Added recursive solve() helper and constructFromPrePost() with postorder index mapping and subtree partition logic
Formatting & Cosmetic
Leetcode/0565-array-nesting/index.md, Leetcode/0936-rle-iterator/index.md
Blank line insertion and removal of stray whitespace around method/field declarations

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • RAJ8664

Poem

🐰 Hop through algorithms with algorithmic cheer!
Eight new Leetcode solutions now crystal clear,
From islands that grow to letters that shift,
Each problem now coded—a problem-solving gift!
With trees, strings, and subarrays stacked high,
This rabbit's solutions reach for the sky!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title is a single period (.) with no descriptive content about the changes made across 10 LeetCode solution files. Replace the title with a descriptive summary of the main changes, such as 'Add C++ solutions for LeetCode problems 565, 854, 878, 892, 900, 901, 905, 920, 925, and 936' or similar.
✅ 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.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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: 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_ and j_ (line 205-206) as renamed indices may reduce readability. Consider names like neighbor_row and neighbor_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

📥 Commits

Reviewing files that changed from the base of the PR and between f504316 and 34d8668.

📒 Files selected for processing (10)
  • Leetcode/0565-array-nesting/index.md
  • Leetcode/0854-making-a-large-island/index.md
  • Leetcode/0878-shifting-letters/index.md
  • Leetcode/0892-shortest-subarray-with-sum-at-least-k/index.md
  • Leetcode/0900-reordered-power-of-2/index.md
  • Leetcode/0901-advantage-shuffle/index.md
  • Leetcode/0905-length-of-longest-fibonacci-subsequence/index.md
  • Leetcode/0920-uncommon-words-from-two-sentences/index.md
  • Leetcode/0925-construct-binary-tree-from-preorder-and-postorder-traversal/index.md
  • Leetcode/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 == 1 captures words appearing exactly once across both inputs.

Leetcode/0901-advantage-shuffle/index.md (1)

68-91: Greedy algorithm is correctly implemented.

The ordered map and upper_bound provide an efficient greedy strategy: for each target, assign the smallest nums1 element that beats it. The fallback to map.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 i is affected by shifts[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 curr and using two pointers to find pairs where arr[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] != 1 on line 168 efficiently prevents revisiting cells during DFS.

@RAJ8664 RAJ8664 merged commit 1da7d9a into RAJ8664:main Dec 29, 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