Skip to content

Conversation

@mitulvaniya
Copy link

@mitulvaniya mitulvaniya commented Oct 19, 2025

Implement the solution for LeetCode problem 283, which moves all zeroes in the array to the end while maintaining the order of non-zero elements.

PR Title Format: Problem no.Problem name.cpp

Intuition

Approach

Code Solution (C++)

    // Your code goes here
    

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

Provide a C++ implementation for LeetCode 283: Move Zeroes with an in-place two-pointer approach, including a vector-print helper and example usage in main.

New Features:

  • Implement C++ solution for LeetCode problem 283 (Move Zeroes) using an in-place two-pointer algorithm
  • Add helper function to print vectors and main function to demonstrate the solution with a sample input

Implement the solution for LeetCode problem 283, which moves all zeroes in the array to the end while maintaining the order of non-zero elements.
@sourcery-ai
Copy link

sourcery-ai bot commented Oct 19, 2025

Reviewer's Guide

Introduces a C++ in-place two-pointer solution for moving zeroes to the end of an array and includes a simple test harness to verify correctness.

Class diagram for Solution and helper functions (LeetCode 283)

classDiagram
    class Solution {
        +void moveZeroes(vector<int>& nums)
    }
    class printVector {
        +void printVector(const vector<int>& nums)
    }
    class main {
        +int main()
    }
    Solution <.. main : uses
    printVector <.. main : uses
Loading

File-Level Changes

Change Details Files
Implemented moveZeroes method using a two-pass in-place approach
  • Declare insertPos pointer for target placement
  • First pass: iterate and copy non-zero elements to insertPos
  • Second pass: fill remaining positions with zeroes
leetcode_283MoveZeroes.cpp
Added helper and test harness to validate the solution
  • Added printVector function to display arrays
  • Added main function with sample input and expected output
leetcode_283MoveZeroes.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:

  • Rename the file to match the project’s naming convention (e.g., "283.MoveZeroes.cpp") instead of "leetcode_283MoveZeroes.cpp".
  • Use size_t for loop indices (e.g., for (size_t i = 0; i < nums.size(); ++i)) to avoid signed/unsigned comparisons.
  • Add more edge-case tests in the main function (empty array, all zeros, all non-zeros) to validate behavior across inputs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Rename the file to match the project’s naming convention (e.g., "283.MoveZeroes.cpp") instead of "leetcode_283MoveZeroes.cpp".
- Use size_t for loop indices (e.g., `for (size_t i = 0; i < nums.size(); ++i)`) to avoid signed/unsigned comparisons.
- Add more edge-case tests in the main function (empty array, all zeros, all non-zeros) to validate behavior across inputs.

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.

@mitulvaniya mitulvaniya changed the title Add solution for LeetCode 283: Move Zeroes 283.MoveZeroes.cpp Oct 19, 2025
@mitulvaniya mitulvaniya marked this pull request as draft October 19, 2025 12:22
@mitulvaniya mitulvaniya marked this pull request as ready for review October 19, 2025 12:22
Updated indexing to use size_t for better compatibility with vector sizes and added edge case tests for the moveZeroes function.
Copy link
Author

@mitulvaniya mitulvaniya left a comment

Choose a reason for hiding this comment

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

i fixed the issue check

@mitulvaniya
Copy link
Author

please merged this pr

@SjxSubham
Copy link
Owner

i fixed the issue check

which Issue ???

@SjxSubham
Copy link
Owner

SjxSubham commented Oct 19, 2025

Hey, @mitulvaniya14

  1. Raise an ISSUE as well if it's not present at the existing Issue list...
  2. Make correction of the PR description.... maintain Proper format check others PRs as well for reference,,,(Add approach , Intuition, code also in that description)
  3. Star the repo as well ⭐

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