-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
feat: add manacher's algorithm #1577
Conversation
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.
Looks good to me.
strings/manacher_algorithm.cpp
Outdated
assert(strings::manacher::manacher("abababc") == "ababa"); | ||
assert(strings::manacher::manacher("cbaabd") == "baab"); | ||
assert(strings::manacher::manacher("xacdedcax") == "xacdedcax"); | ||
assert(strings::manacher::manacher("xacddcax") == "xacddcax"); |
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.
Add some test cases with Upper , Mixed, camel Case. Test Cases format seem to be repeativie.
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.
LGTM
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.
Great work, @riti2409! Thanks for reviewing, @b30wulffz, @vid-7695, and @shikhar-psyduck. 🙂
Also, please fix clang-tidy
warnings.
strings/manacher_algorithm.cpp
Outdated
@@ -0,0 +1,165 @@ | |||
/** | |||
* @file | |||
* @brief Implementation of the |
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.
* @brief Implementation of the | |
* @brief Implementation of |
strings/manacher_algorithm.cpp
Outdated
#include <cassert> // for asserting test cases | ||
#include <iostream> // for IO operations |
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 <cassert> // for asserting test cases | |
#include <iostream> // for IO operations | |
#include <cassert> /// for assert | |
#include <iostream> /// for IO operations |
strings/manacher_algorithm.cpp
Outdated
#include <cassert> // for asserting test cases | ||
#include <iostream> // for IO operations | ||
#ifdef _MSC_VER | ||
#include <string> // required for MS Visual C++ |
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 <string> // required for MS Visual C++ | |
#include <string> /// required for MS Visual C++ |
strings/manacher_algorithm.cpp
Outdated
#ifdef _MSC_VER | ||
#include <string> // required for MS Visual C++ | ||
#else | ||
#include <cstring> |
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.
Add a one-line description here as in line 17.
strings/manacher_algorithm.cpp
Outdated
/** | ||
* @brief A function that implements Manacher's algorithm | ||
* @param prototype is the string where algorithm finds a palindromic substring. | ||
* This string can contain any character except @ # & |
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.
* This string can contain any character except @ # & | |
* This string can contain any character except `@` `#` `&` |
strings/manacher_algorithm.cpp
Outdated
int main() { | ||
test(); // run self-test implementations | ||
return 0; | ||
} |
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.
} | |
} | |
6da2c55
@Panquesito7 I have incorporated all the suggestions. Please review. |
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.
Almost there! 😄
strings/manacher_algorithm.cpp
Outdated
|
||
#include <cassert> /// for assert | ||
#include <iostream> /// for IO operations | ||
#include <vector> /// for vector STL |
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> /// for vector STL | |
#include <vector> /// for std::vector STL |
@Panquesito7 Done 😀 |
strings/manacher_algorithm.cpp
Outdated
// stuffed string). This value will be lower bound of half | ||
// length since single character is a palindrome in itself. | ||
|
||
int bigger_center = |
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.
Consider using uint64_t
for non-negative values (or their appropriate size: uint32_t
, uint16_t
, uint8_t
) or int64_t
for negative values. Check other parts of the code (reference). 🙂
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.
@Panquesito7 Sure, Updated
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.
Awesome work, @riti2409! Thanks for your contribution! 😄👍🎉
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.
Oh, you just missed one thing: please fix clang-tidy
warnings.
@Panquesito7 Compile checks for "Awesome CI Workflow / Compile checks (windows-latest) (pull_request)" failed to run because of some server issue in the VM. Is it possible to rerun the checks? Edit: I am pushing a small commit to rerun the checks. |
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.
Awesome work, @riti2409! It's been great for your first contribution here! Thank you; we hope you keep contributing. 😄 👍 🎉
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.
LGTM 👍
@Panquesito7 Thanks for encouraging :) |
Description of Change
Checklist
Notes: This is an implementation of the Manacher's Algorithm which is used to find the longest substring in linear time.