Skip to content

Conversation

@gg21-prog
Copy link
Contributor

@gg21-prog gg21-prog commented Oct 29, 2025

PR Title: 3350. Adjacent Increasing Subarrays Detection II.cpp

Solution for issue #274

Intuition:
The goal is to find the longest point in the array where two strictly increasing parts appear one after another. Instead of checking every subarray, we track how long each increasing streak continues and use that to figure out where two valid segments can exist.

Approach:
First, build an array that stores the length of the current increasing streak ending at each position.
Then use binary search on k, the possible subarray length, to find the largest value for which two consecutive increasing parts of size k exist.
This approach is efficient because it relies on precomputed streaks rather than brute-force comparisons.

Complexity:
Time: O(n log n) due to binary search over possible lengths combined with linear checks.
Space: O(n) for storing streak lengths.

Key Takeaway:
By observing how long each part of the array keeps increasing, we can easily spot where two upward trends align. It’s a simple pattern-based way to solve the problem without unnecessary computation.

By submitting this PR, I confirm that:

  • This is my original work not totally AI generated
  • I have tested the solution thoroughly on leetcode
  • I have maintained proper PR description format
  • This is a meaningful contribution, not spam

Summary by Sourcery

Add a C++ implementation that computes the longest adjacent strictly increasing subarrays by preprocessing streak lengths and using binary search to find the optimal segment length.

New Features:

  • Implement C++ solution for LeetCode 3350: Adjacent Increasing Subarrays Detection II.

Enhancements:

  • Use an auxiliary array to track increasing streak lengths at each position.
  • Apply binary search to efficiently determine the maximum k for two adjacent increasing segments.

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 29, 2025

Reviewer's Guide

Implements a C++ solution that precomputes increasing streak lengths and performs a binary search over possible subarray length k to detect the maximum k for which two adjacent strictly increasing subarrays exist.

Class diagram for the new solution functions

classDiagram
class check {
  +bool check(int *inc, int n, int k)
}
class maxIncreasingSubarrays {
  +int maxIncreasingSubarrays(int *nums, int numsSize)
}
maxIncreasingSubarrays --> check : calls
Loading

Flow diagram for the algorithm to find maximum adjacent increasing subarrays

flowchart TD
    A["Input: nums array"] --> B["Compute inc[]: increasing streak lengths"]
    B --> C["Binary search for k"]
    C --> D["For each candidate k, call check(inc, n, k)"]
    D -->|If two adjacent increasing subarrays of length k exist| E["Update answer and try larger k"]
    D -->|Else| F["Try smaller k"]
    E --> C
    F --> C
    C --> G["Return max k found"]
Loading

File-Level Changes

Change Details Files
Compute and store increasing streak lengths
  • Declare and initialize inc array to all ones
  • Single-pass loop to update streak lengths when nums[i] > nums[i-1]
3350. Adjacent Increasing Subarrays Detection II.cpp
Add helper function to check adjacent increasing subarrays
  • Introduce check() to scan for two segments of length k using inc array
  • Loop end positions and return true if both segments satisfy inc >= k
3350. Adjacent Increasing Subarrays Detection II.cpp
Use binary search to find maximum k
  • Set search bounds L=1, R=n/2 and ans=0
  • Iteratively adjust bounds based on check() results and update ans
3350. Adjacent Increasing Subarrays Detection II.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Thanks for raising the PR, the owner will be review it soon' keep patience, keep contributing>>>!!! make sure you have star ⭐ the repo

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Use std::vector for the streak lengths (and adjust the function signature) instead of a C‐style VLA to improve safety and standards compliance.
  • Add an early return for numsSize < 2 (or k <= 0) to handle trivial inputs without running the full binary search.
  • Rename the 'check' function to something more descriptive (e.g. hasAdjacentIncreasingSubarrays) so its intent is clearer.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Use std::vector<int> for the streak lengths (and adjust the function signature) instead of a C‐style VLA to improve safety and standards compliance.
- Add an early return for numsSize < 2 (or k <= 0) to handle trivial inputs without running the full binary search.
- Rename the 'check' function to something more descriptive (e.g. hasAdjacentIncreasingSubarrays) so its intent is clearer.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@SjxSubham
Copy link
Owner

@gg21-prog made these changes

  1. rename PR title
  2. raise an ISSUE as well regarding this problem...

@gg21-prog gg21-prog changed the title Add solution for LeetCode 3350: Adjacent Increasing Subarrays Detecti… 3350. Adjacent Increasing Subarrays Detection II.cpp Oct 30, 2025
@gg21-prog
Copy link
Contributor Author

@SjxSubham done!

@SjxSubham SjxSubham linked an issue Oct 30, 2025 that may be closed by this pull request
4 tasks
@SjxSubham
Copy link
Owner

@gg21-prog star the repo as well

@gg21-prog
Copy link
Contributor Author

done!

@SjxSubham SjxSubham merged commit 92c8692 into SjxSubham:main Oct 31, 2025
2 checks passed
@github-actions
Copy link

🎉 Congrats on getting your PR merged in, @gg21-prog! 🙌🏼

Thanks for your contribution every effort helps improve the project.

Looking forward to seeing more from you! 🥳✨

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.

3350. Adjacent Increasing Subarrays Detection II.cpp

2 participants