Skip to content

Conversation

DataWorshipper
Copy link

@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

#include <cassert> /// for assert
#include <cstdint>
#include <iostream> /// for IO operations
#include <vector>
Copy link
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 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
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
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 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
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.

int main() {
test(); // run self-test implementations
return 0;
} No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
}
}

@DataWorshipper
Copy link
Author

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

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