Skip to content

Conversation

@PralayeshMukherjee
Copy link
Contributor

@PralayeshMukherjee PralayeshMukherjee commented Oct 18, 2025

PR Title Format: Problem no.Problem name.cpp

Intuition

This is vary easy question you can solve it easily.
let suppose,
nums = [1,1,0,1,1,1]
so maximum consecutive once is 3
go through the approach

Approach

  1. init two variable one for store the max value and one for count the once

  2. iterate the nums array
    if nums[i] = 1 then increase the count by 1 and store the maximun value between nums[i] and max
    But if we encounted by 0 then set the count variable to 0

  3. return the max value

Code Solution (C++)

    // Your code goes here
    class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int max = 0;
        int count = 0;
        for(int i=0;i<nums.size();i++){
            if(nums[i]==1){
                count++;
                if(max<count){
                    max = count;
                }
            }else{
                count = 0;
            }
        }
        return max;
    }
};

Related Issues

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

New Features:

  • Implement findMaxConsecutiveOnes method that returns the longest run of 1s in a binary vector.

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 18, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a new C++ solution for finding the maximum number of consecutive ones in a binary array using a single-pass linear scan with two counters.

Class diagram for the new Solution class (max consecutive ones)

classDiagram
class Solution {
  +int findMaxConsecutiveOnes(vector<int>& nums)
}
Loading

File-Level Changes

Change Details Files
Implemented findMaxConsecutiveOnes method with two-counter approach
  • Initialized 'max' and 'count' variables
  • Iterated through the input vector with a single for loop
  • Incremented count on encountering 1 and reset on 0
  • Updated max when count exceeded current max
  • Returned the computed max value
485. Max Consecutive Ones.cpp

Possibly linked issues

  • #485: The PR implements the exact C++ solution for LeetCode problem 485, Max Consecutive Ones, as described in the issue.

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

@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 and they look great!


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 SjxSubham changed the title Implement solution for max consecutive ones problem 838. Push Dominoes.cpp Oct 18, 2025
@SjxSubham SjxSubham changed the title 838. Push Dominoes.cpp 485. Max Consecutive Ones.cpp Oct 18, 2025
@SjxSubham SjxSubham added the hacktoberest-accepted hacktoberfest-accepted label Oct 18, 2025
@SjxSubham
Copy link
Owner

@PralayeshMukherjee
Thanks for the PR,,,

Happy HAcktober...

@SjxSubham SjxSubham merged commit 9bf8dc4 into SjxSubham:main Oct 18, 2025
2 checks passed
@SjxSubham SjxSubham linked an issue Oct 25, 2025 that may be closed by this pull request
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hacktoberest-accepted hacktoberfest-accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

485. Max Consecutive Ones.cpp

2 participants