-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add Sliding Window XOR algorithm in C++ with test cases #3023
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add Sliding Window XOR algorithm in C++ with test cases #3023
Conversation
#include <cassert> /// for assert | ||
#include <cstdint> | ||
#include <iostream> /// for IO operations | ||
#include <vector> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <vector> | |
#include <vector> /// for std::vector |
* @param a Multiplier in array generation | ||
* @param b Increment in array generation | ||
* @param c Modulo in array generation |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
std::uint64_t l = 0; // Left pointer of sliding window | ||
std::uint64_t r = 0; // Right pointer of sliding window |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | |
} | |
Hello ,so i have refactored the variable names and added the changes that you requested ,could you take a look at it now |
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 ofn
integers generated using the recurrence relation: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