Skip to content

Add Sliding Window XOR algorithm in C++ with test cases#3023

Closed
DataWorshipper wants to merge 7 commits intoTheAlgorithms:masterfrom
DataWorshipper:sliding_window_xor1
Closed

Add Sliding Window XOR algorithm in C++ with test cases#3023
DataWorshipper wants to merge 7 commits intoTheAlgorithms:masterfrom
DataWorshipper:sliding_window_xor1

Conversation

@DataWorshipper
Copy link
Copy Markdown

@DataWorshipper DataWorshipper commented Oct 2, 2025

Description of Change

This pull request adds a C++ implementation of the Sliding Window XOR problem to the Bit Manipulation section.

The algorithm calculates the bitwise XOR of every window of size k in an array of n integers generated using the recurrence relation:

arr[0] = x;                 // first element
arr[i] = (a * arr[i-1] + b) % c;  // for i = 1 to n-1

It maintains a sliding window of size k using two pointers, efficiently computing the cumulative XOR of all windows in O(n) time with O(n) space.

The submission is self-contained, with detailed Doxygen documentation and a test() function that includes multiple verified test cases to ensure correctness.

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational (Doxygen guidelines)
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate
  • I acknowledge that all my contributions will be made under the project's license

Comment thread bit_manipulation/sliding_window_xor.cpp Outdated
Comment thread bit_manipulation/sliding_window_xor.cpp Outdated
#include <cassert> /// for assert
#include <cstdint>
#include <iostream> /// for IO operations
#include <vector>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <vector>
#include <vector> /// for std::vector

Comment thread bit_manipulation/sliding_window_xor.cpp Outdated
Comment on lines +39 to +41
* @param a Multiplier in array generation
* @param b Increment in array generation
* @param c Modulo in array generation
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

These variable names could be longer.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

These variables were in the problem statement ,i think it would be intuitive for the user who is following the problem statement

Comment thread bit_manipulation/sliding_window_xor.cpp Outdated
Comment on lines +67 to +68
std::uint64_t l = 0; // Left pointer of sliding window
std::uint64_t r = 0; // Right pointer of sliding window
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could name these to be left and right, respectively.

Comment thread bit_manipulation/sliding_window_xor.cpp Outdated
@DataWorshipper
Copy link
Copy Markdown
Author

Hello ,so i have refactored the variable names and added the changes that you requested ,could you take a look at it now

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Author has not responded to the comments for over 2 weeks label Nov 12, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!

@github-actions github-actions Bot closed this Nov 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Author has not responded to the comments for over 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants