Skip to content

Instantly share code, notes, and snippets.

View dhaval-shownkani's full-sized avatar

dhaval-shownkani

View GitHub Profile
@dhaval-shownkani
dhaval-shownkani / gist:3731736
Created September 16, 2012 09:24
find the largest substring palindrome in a given string in linear time
#include<iostream.h>
#include<string.h>
// Transform S into T.
// For example, S = "abba", T = "^#a#b#b#a#$".
// ^ and $ signs are sentinels appended to each end to avoid bounds checking
string preProcess(string s) {
int n = s.length();
if (n == 0) return "^$";
string ret = "^";
for (int i = 0; i < n; i++)